gifted-baileys 1.5.0 → 1.5.5
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 +1429 -684
- package/package.json +11 -26
- package/src/Defaults/baileys-version.json +3 -0
- package/{lib → src}/Defaults/index.js +16 -8
- package/src/Defaults/index.ts +131 -0
- package/src/Defaults/phonenumber-mcc.json +223 -0
- package/src/Signal/libsignal.js +180 -0
- package/src/Signal/libsignal.ts +141 -0
- package/src/Socket/Client/abstract-socket-client.ts +19 -0
- package/src/Socket/Client/index.ts +3 -0
- package/src/Socket/Client/mobile-socket-client.js +78 -0
- package/src/Socket/Client/mobile-socket-client.ts +66 -0
- package/src/Socket/Client/web-socket-client.js +75 -0
- package/src/Socket/Client/web-socket-client.ts +57 -0
- package/{lib → src}/Socket/business.js +33 -27
- package/src/Socket/business.ts +281 -0
- package/{lib → src}/Socket/chats.js +197 -178
- package/src/Socket/chats.ts +1030 -0
- package/{lib → src}/Socket/groups.js +69 -79
- package/src/Socket/groups.ts +356 -0
- package/{lib → src}/Socket/index.js +1 -4
- package/src/Socket/index.ts +13 -0
- package/{lib → src}/Socket/messages-recv.js +160 -108
- package/src/Socket/messages-recv.ts +985 -0
- package/{lib → src}/Socket/messages-send.js +183 -100
- package/src/Socket/messages-send.ts +871 -0
- package/src/Socket/newsletter.js +227 -0
- package/src/Socket/newsletter.ts +282 -0
- package/{lib → src}/Socket/registration.js +55 -63
- package/src/Socket/registration.ts +250 -0
- package/{lib → src}/Socket/socket.js +107 -66
- package/src/Socket/socket.ts +777 -0
- package/src/Store/index.ts +3 -0
- package/{lib → src}/Store/make-cache-manager-store.js +34 -25
- package/src/Store/make-cache-manager-store.ts +100 -0
- package/{lib → src}/Store/make-in-memory-store.js +51 -61
- package/src/Store/make-in-memory-store.ts +475 -0
- package/src/Store/make-ordered-dictionary.ts +86 -0
- package/{lib → src}/Store/object-repository.js +1 -1
- package/src/Store/object-repository.ts +32 -0
- package/src/Tests/test.app-state-sync.js +204 -0
- package/src/Tests/test.app-state-sync.ts +207 -0
- package/src/Tests/test.event-buffer.js +270 -0
- package/src/Tests/test.event-buffer.ts +319 -0
- package/src/Tests/test.key-store.js +76 -0
- package/src/Tests/test.key-store.ts +92 -0
- package/src/Tests/test.libsignal.js +141 -0
- package/src/Tests/test.libsignal.ts +186 -0
- package/src/Tests/test.media-download.js +93 -0
- package/src/Tests/test.media-download.ts +76 -0
- package/src/Tests/test.messages.js +33 -0
- package/src/Tests/test.messages.ts +37 -0
- package/src/Tests/utils.js +34 -0
- package/src/Tests/utils.ts +36 -0
- package/src/Types/Auth.ts +113 -0
- package/src/Types/Call.ts +15 -0
- package/src/Types/Chat.ts +106 -0
- package/{lib/Types/Contact.d.ts → src/Types/Contact.ts} +9 -8
- package/src/Types/Events.ts +93 -0
- package/src/Types/GroupMetadata.ts +53 -0
- package/{lib → src}/Types/Label.js +1 -1
- package/src/Types/Label.ts +36 -0
- package/{lib → src}/Types/LabelAssociation.js +1 -1
- package/{lib/Types/LabelAssociation.d.ts → src/Types/LabelAssociation.ts} +22 -16
- package/src/Types/Message.ts +288 -0
- package/src/Types/Newsletter.js +32 -0
- package/src/Types/Newsletter.ts +98 -0
- package/src/Types/Product.ts +85 -0
- package/src/Types/Signal.ts +68 -0
- package/{lib/Types/Socket.d.ts → src/Types/Socket.ts} +68 -56
- package/src/Types/State.ts +29 -0
- package/{lib → src}/Types/index.js +2 -1
- package/src/Types/index.ts +59 -0
- package/{lib → src}/Utils/auth-utils.js +95 -76
- package/src/Utils/auth-utils.ts +222 -0
- package/src/Utils/baileys-event-stream.js +92 -0
- package/src/Utils/baileys-event-stream.ts +66 -0
- package/{lib → src}/Utils/business.js +45 -17
- package/src/Utils/business.ts +275 -0
- package/{lib → src}/Utils/chat-utils.js +74 -46
- package/src/Utils/chat-utils.ts +860 -0
- package/{lib → src}/Utils/crypto.js +31 -21
- package/src/Utils/crypto.ts +131 -0
- package/src/Utils/decode-wa-message.js +211 -0
- package/src/Utils/decode-wa-message.ts +228 -0
- package/{lib → src}/Utils/event-buffer.js +13 -4
- package/src/Utils/event-buffer.ts +613 -0
- package/{lib → src}/Utils/generics.js +98 -45
- package/src/Utils/generics.ts +434 -0
- package/{lib → src}/Utils/history.js +39 -10
- package/src/Utils/history.ts +112 -0
- package/src/Utils/index.ts +17 -0
- package/{lib → src}/Utils/link-preview.js +54 -17
- package/src/Utils/link-preview.ts +122 -0
- package/src/Utils/logger.ts +3 -0
- package/src/Utils/lt-hash.ts +61 -0
- package/{lib → src}/Utils/make-mutex.js +13 -4
- package/src/Utils/make-mutex.ts +44 -0
- package/{lib → src}/Utils/messages-media.js +296 -192
- package/src/Utils/messages-media.ts +847 -0
- package/{lib → src}/Utils/messages.js +124 -113
- package/src/Utils/messages.ts +956 -0
- package/{lib → src}/Utils/noise-handler.js +16 -3
- package/src/Utils/noise-handler.ts +197 -0
- package/{lib → src}/Utils/process-message.js +33 -29
- package/src/Utils/process-message.ts +414 -0
- package/{lib → src}/Utils/signal.js +23 -14
- package/src/Utils/signal.ts +177 -0
- package/{lib → src}/Utils/use-multi-file-auth-state.js +28 -19
- package/src/Utils/use-multi-file-auth-state.ts +90 -0
- package/{lib → src}/Utils/validate-connection.js +25 -42
- package/src/Utils/validate-connection.ts +238 -0
- package/src/WABinary/constants.ts +42 -0
- package/{lib → src}/WABinary/decode.js +17 -7
- package/src/WABinary/decode.ts +265 -0
- package/{lib → src}/WABinary/encode.js +17 -7
- package/src/WABinary/encode.ts +236 -0
- package/{lib → src}/WABinary/generic-utils.js +2 -2
- package/src/WABinary/generic-utils.ts +121 -0
- package/src/WABinary/index.ts +5 -0
- package/{lib → src}/WABinary/jid-utils.js +4 -1
- package/src/WABinary/jid-utils.ts +68 -0
- package/src/WABinary/types.ts +17 -0
- package/src/WAM/BinaryInfo.js +13 -0
- package/src/WAM/BinaryInfo.ts +12 -0
- package/src/WAM/constants.js +15350 -0
- package/src/WAM/constants.ts +15382 -0
- package/src/WAM/encode.js +155 -0
- package/src/WAM/encode.ts +174 -0
- package/src/WAM/index.js +19 -0
- package/src/WAM/index.ts +3 -0
- package/src/gifted +1 -0
- package/{lib → src}/index.js +1 -0
- package/src/index.ts +13 -0
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/index.d.ts +0 -284
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/libsignal.d.ts +0 -3
- package/lib/Signal/libsignal.js +0 -152
- package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
- package/lib/Socket/Client/index.d.ts +0 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.d.ts +0 -12
- package/lib/Socket/Client/web-socket-client.js +0 -62
- package/lib/Socket/business.d.ts +0 -135
- package/lib/Socket/chats.d.ts +0 -79
- package/lib/Socket/groups.d.ts +0 -113
- package/lib/Socket/index.d.ts +0 -137
- package/lib/Socket/messages-recv.d.ts +0 -124
- package/lib/Socket/messages-send.d.ts +0 -119
- package/lib/Socket/registration.d.ts +0 -232
- package/lib/Socket/socket.d.ts +0 -42
- package/lib/Store/index.d.ts +0 -3
- package/lib/Store/make-cache-manager-store.d.ts +0 -13
- package/lib/Store/make-in-memory-store.d.ts +0 -117
- package/lib/Store/make-ordered-dictionary.d.ts +0 -13
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Types/Auth.d.ts +0 -108
- package/lib/Types/Call.d.ts +0 -13
- package/lib/Types/Chat.d.ts +0 -102
- package/lib/Types/Events.d.ts +0 -157
- package/lib/Types/GroupMetadata.d.ts +0 -52
- package/lib/Types/Label.d.ts +0 -35
- package/lib/Types/Message.d.ts +0 -261
- package/lib/Types/Product.d.ts +0 -78
- package/lib/Types/Signal.d.ts +0 -57
- package/lib/Types/State.d.ts +0 -27
- package/lib/Types/index.d.ts +0 -56
- package/lib/Utils/auth-utils.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.d.ts +0 -16
- package/lib/Utils/baileys-event-stream.js +0 -63
- package/lib/Utils/business.d.ts +0 -22
- package/lib/Utils/chat-utils.d.ts +0 -71
- package/lib/Utils/crypto.d.ts +0 -41
- package/lib/Utils/decode-wa-message.d.ts +0 -19
- package/lib/Utils/decode-wa-message.js +0 -174
- package/lib/Utils/event-buffer.d.ts +0 -35
- package/lib/Utils/generics.d.ts +0 -94
- package/lib/Utils/history.d.ts +0 -15
- package/lib/Utils/index.d.ts +0 -17
- package/lib/Utils/link-preview.d.ts +0 -21
- package/lib/Utils/logger.d.ts +0 -4
- package/lib/Utils/lt-hash.d.ts +0 -12
- package/lib/Utils/make-mutex.d.ts +0 -7
- package/lib/Utils/messages-media.d.ts +0 -107
- package/lib/Utils/messages.d.ts +0 -76
- package/lib/Utils/noise-handler.d.ts +0 -20
- package/lib/Utils/process-message.d.ts +0 -41
- package/lib/Utils/signal.d.ts +0 -32
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -12
- package/lib/Utils/validate-connection.d.ts +0 -11
- package/lib/WABinary/constants.d.ts +0 -27
- package/lib/WABinary/decode.d.ts +0 -7
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/generic-utils.d.ts +0 -15
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/jid-utils.d.ts +0 -29
- package/lib/WABinary/types.d.ts +0 -18
- package/lib/index.d.ts +0 -10
- /package/{lib → src}/Socket/Client/abstract-socket-client.js +0 -0
- /package/{lib → src}/Socket/Client/index.js +0 -0
- /package/{lib → src}/Store/index.js +0 -0
- /package/{lib → src}/Store/make-ordered-dictionary.js +0 -0
- /package/{lib → src}/Types/Auth.js +0 -0
- /package/{lib → src}/Types/Call.js +0 -0
- /package/{lib → src}/Types/Chat.js +0 -0
- /package/{lib → src}/Types/Contact.js +0 -0
- /package/{lib → src}/Types/Events.js +0 -0
- /package/{lib → src}/Types/GroupMetadata.js +0 -0
- /package/{lib → src}/Types/Message.js +0 -0
- /package/{lib → src}/Types/Product.js +0 -0
- /package/{lib → src}/Types/Signal.js +0 -0
- /package/{lib → src}/Types/Socket.js +0 -0
- /package/{lib → src}/Types/State.js +0 -0
- /package/{lib → src}/Utils/index.js +0 -0
- /package/{lib → src}/Utils/logger.js +0 -0
- /package/{lib → src}/Utils/lt-hash.js +0 -0
- /package/{lib → src}/WABinary/constants.js +0 -0
- /package/{lib → src}/WABinary/index.js +0 -0
- /package/{lib → src}/WABinary/types.js +0 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gifted-baileys",
|
|
3
|
-
"version": "1.5.
|
|
4
|
-
"description": "WhatsApp
|
|
3
|
+
"version": "1.5.5",
|
|
4
|
+
"description": "Typescript/Javascript WhatsApp Web API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"whatsapp",
|
|
7
7
|
"js-whatsapp",
|
|
@@ -14,35 +14,19 @@
|
|
|
14
14
|
"automation",
|
|
15
15
|
"multi-device"
|
|
16
16
|
],
|
|
17
|
-
"homepage": "https://
|
|
17
|
+
"homepage": "https://baileys.giftedtech.web.id",
|
|
18
18
|
"repository": {
|
|
19
|
-
"url": "
|
|
19
|
+
"url": "https://baileys.giftedtech.web.id"
|
|
20
20
|
},
|
|
21
21
|
"license": "MIT",
|
|
22
|
-
"author": "
|
|
23
|
-
"main": "
|
|
24
|
-
"types": "
|
|
22
|
+
"author": "GiftedTech",
|
|
23
|
+
"main": "src/index.js",
|
|
24
|
+
"types": "src/index.d.ts",
|
|
25
25
|
"files": [
|
|
26
|
-
"
|
|
26
|
+
"src/*",
|
|
27
27
|
"WAProto/*",
|
|
28
28
|
"WASignalGroup/*.js"
|
|
29
29
|
],
|
|
30
|
-
"scripts": {
|
|
31
|
-
"build:all": "tsc && typedoc",
|
|
32
|
-
"build:docs": "typedoc",
|
|
33
|
-
"build:tsc": "tsc",
|
|
34
|
-
"changelog:last": "conventional-changelog -p angular -r 2",
|
|
35
|
-
"changelog:preview": "conventional-changelog -p angular -u",
|
|
36
|
-
"changelog:update": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
|
|
37
|
-
"example": "node --inspect -r ts-node/register Example/example.ts",
|
|
38
|
-
"gen:protobuf": "sh WAProto/GenerateStatics.sh",
|
|
39
|
-
"lint": "eslint src --ext .js,.ts,.jsx,.tsx",
|
|
40
|
-
"lint:fix": "eslint src --fix --ext .js,.ts,.jsx,.tsx",
|
|
41
|
-
"prepack": "tsc",
|
|
42
|
-
"prepare": "tsc",
|
|
43
|
-
"release": "release-it",
|
|
44
|
-
"test": "jest"
|
|
45
|
-
},
|
|
46
30
|
"dependencies": {
|
|
47
31
|
"@adiwajshing/keyed-db": "^0.2.4",
|
|
48
32
|
"@hapi/boom": "^9.1.3",
|
|
@@ -69,7 +53,7 @@
|
|
|
69
53
|
"conventional-changelog-cli": "^2.2.2",
|
|
70
54
|
"eslint": "^8.0.0",
|
|
71
55
|
"jest": "^27.0.6",
|
|
72
|
-
"jimp": "^0.
|
|
56
|
+
"jimp": "^0.22.12",
|
|
73
57
|
"link-preview-js": "^3.0.0",
|
|
74
58
|
"open": "^8.4.2",
|
|
75
59
|
"qrcode-terminal": "^0.12.0",
|
|
@@ -78,7 +62,8 @@
|
|
|
78
62
|
"ts-jest": "^27.0.3",
|
|
79
63
|
"ts-node": "^10.8.1",
|
|
80
64
|
"typedoc": "^0.24.7",
|
|
81
|
-
"typescript": "^4.6.4"
|
|
65
|
+
"typescript": "^4.6.4",
|
|
66
|
+
"json": "^11.0.0"
|
|
82
67
|
},
|
|
83
68
|
"peerDependencies": {
|
|
84
69
|
"jimp": "^0.16.1",
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
5
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.DEFAULT_CACHE_TTLS = exports.INITIAL_PREKEY_COUNT = exports.MIN_PREKEY_COUNT = exports.MEDIA_KEYS = exports.MEDIA_HKDF_KEY_MAPPING = exports.MEDIA_PATH_MAP = exports.DEFAULT_CONNECTION_CONFIG = exports.PROCESSABLE_HISTORY_TYPES = exports.WA_CERT_DETAILS = exports.
|
|
15
|
+
exports.DEFAULT_CACHE_TTLS = exports.INITIAL_PREKEY_COUNT = exports.MIN_PREKEY_COUNT = exports.MEDIA_KEYS = exports.MEDIA_HKDF_KEY_MAPPING = exports.MEDIA_PATH_MAP = exports.DEFAULT_CONNECTION_CONFIG = exports.PROCESSABLE_HISTORY_TYPES = exports.WA_CERT_DETAILS = exports.URL_REGEX = exports.MOBILE_NOISE_HEADER = exports.PROTOCOL_VERSION = exports.NOISE_WA_HEADER = exports.KEY_BUNDLE_TYPE = exports.DICT_VERSION = exports.NOISE_MODE = exports.REGISTRATION_PUBLIC_KEY = exports.MOBILE_USERAGENT = exports.MOBILE_REGISTRATION_ENDPOINT = exports.MOBILE_TOKEN = exports.WA_DEFAULT_EPHEMERAL = exports.PHONE_CONNECTION_CB = exports.DEF_TAG_PREFIX = exports.DEF_CALLBACK_PREFIX = exports.MOBILE_PORT = exports.MOBILE_ENDPOINT = exports.DEFAULT_ORIGIN = exports.PHONENUMBER_MCC = exports.UNAUTHORIZED_CODES = void 0;
|
|
7
16
|
const crypto_1 = require("crypto");
|
|
8
17
|
const WAProto_1 = require("../../WAProto");
|
|
9
18
|
const libsignal_1 = require("../Signal/libsignal");
|
|
@@ -20,7 +29,7 @@ exports.DEF_CALLBACK_PREFIX = 'CB:';
|
|
|
20
29
|
exports.DEF_TAG_PREFIX = 'TAG:';
|
|
21
30
|
exports.PHONE_CONNECTION_CB = 'CB:Pong';
|
|
22
31
|
exports.WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60;
|
|
23
|
-
const WA_VERSION = '2.
|
|
32
|
+
const WA_VERSION = '2.24.6.77';
|
|
24
33
|
const WA_VERSION_HASH = (0, crypto_1.createHash)('md5').update(WA_VERSION).digest('hex');
|
|
25
34
|
exports.MOBILE_TOKEN = Buffer.from('0a1mLfGUIBVrMKF1RdvLI5lkRBvof6vn0fD2QRSM' + WA_VERSION_HASH);
|
|
26
35
|
exports.MOBILE_REGISTRATION_ENDPOINT = 'https://v.whatsapp.net/v2';
|
|
@@ -37,7 +46,6 @@ exports.PROTOCOL_VERSION = [5, 2];
|
|
|
37
46
|
exports.MOBILE_NOISE_HEADER = Buffer.concat([Buffer.from('WA'), Buffer.from(exports.PROTOCOL_VERSION)]);
|
|
38
47
|
/** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
|
|
39
48
|
exports.URL_REGEX = /(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/;
|
|
40
|
-
exports.URL_EXCLUDE_REGEX = /.*@.*/;
|
|
41
49
|
exports.WA_CERT_DETAILS = {
|
|
42
50
|
SERIAL: 0,
|
|
43
51
|
};
|
|
@@ -49,7 +57,7 @@ exports.PROCESSABLE_HISTORY_TYPES = [
|
|
|
49
57
|
];
|
|
50
58
|
exports.DEFAULT_CONNECTION_CONFIG = {
|
|
51
59
|
version: baileys_version_json_1.version,
|
|
52
|
-
browser: Utils_1.Browsers.
|
|
60
|
+
browser: Utils_1.Browsers.ubuntu('Chrome'),
|
|
53
61
|
waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
|
|
54
62
|
connectTimeoutMs: 20000,
|
|
55
63
|
keepAliveIntervalMs: 30000,
|
|
@@ -75,7 +83,7 @@ exports.DEFAULT_CONNECTION_CONFIG = {
|
|
|
75
83
|
patch: false,
|
|
76
84
|
snapshot: false,
|
|
77
85
|
},
|
|
78
|
-
getMessage:
|
|
86
|
+
getMessage: () => __awaiter(void 0, void 0, void 0, function* () { return undefined; }),
|
|
79
87
|
makeSignalRepository: libsignal_1.makeLibSignalRepository
|
|
80
88
|
};
|
|
81
89
|
exports.MEDIA_PATH_MAP = {
|
|
@@ -113,8 +121,8 @@ exports.MEDIA_KEYS = Object.keys(exports.MEDIA_PATH_MAP);
|
|
|
113
121
|
exports.MIN_PREKEY_COUNT = 5;
|
|
114
122
|
exports.INITIAL_PREKEY_COUNT = 30;
|
|
115
123
|
exports.DEFAULT_CACHE_TTLS = {
|
|
116
|
-
SIGNAL_STORE: 5 * 60,
|
|
117
|
-
MSG_RETRY: 60 * 60,
|
|
118
|
-
CALL_OFFER: 5 * 60,
|
|
124
|
+
SIGNAL_STORE: 5 * 60, // 5 minutes
|
|
125
|
+
MSG_RETRY: 60 * 60, // 1 hour
|
|
126
|
+
CALL_OFFER: 5 * 60, // 5 minutes
|
|
119
127
|
USER_DEVICES: 5 * 60, // 5 minutes
|
|
120
128
|
};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { createHash } from 'crypto'
|
|
2
|
+
import { proto } from '../../WAProto'
|
|
3
|
+
import { makeLibSignalRepository } from '../Signal/libsignal'
|
|
4
|
+
import type { AuthenticationState, MediaType, SocketConfig, WAVersion } from '../Types'
|
|
5
|
+
import { Browsers } from '../Utils'
|
|
6
|
+
import logger from '../Utils/logger'
|
|
7
|
+
import { version } from './baileys-version.json'
|
|
8
|
+
import phoneNumberMCC from './phonenumber-mcc.json'
|
|
9
|
+
|
|
10
|
+
export const UNAUTHORIZED_CODES = [401, 403, 419]
|
|
11
|
+
|
|
12
|
+
export const PHONENUMBER_MCC = phoneNumberMCC
|
|
13
|
+
|
|
14
|
+
export const DEFAULT_ORIGIN = 'https://web.whatsapp.com'
|
|
15
|
+
export const MOBILE_ENDPOINT = 'g.whatsapp.net'
|
|
16
|
+
export const MOBILE_PORT = 443
|
|
17
|
+
export const DEF_CALLBACK_PREFIX = 'CB:'
|
|
18
|
+
export const DEF_TAG_PREFIX = 'TAG:'
|
|
19
|
+
export const PHONE_CONNECTION_CB = 'CB:Pong'
|
|
20
|
+
|
|
21
|
+
export const WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60
|
|
22
|
+
|
|
23
|
+
const WA_VERSION = '2.24.6.77'
|
|
24
|
+
|
|
25
|
+
const WA_VERSION_HASH = createHash('md5').update(WA_VERSION).digest('hex')
|
|
26
|
+
export const MOBILE_TOKEN = Buffer.from('0a1mLfGUIBVrMKF1RdvLI5lkRBvof6vn0fD2QRSM' + WA_VERSION_HASH)
|
|
27
|
+
export const MOBILE_REGISTRATION_ENDPOINT = 'https://v.whatsapp.net/v2'
|
|
28
|
+
export const MOBILE_USERAGENT = `WhatsApp/${WA_VERSION} iOS/15.3.1 Device/Apple-iPhone_7`
|
|
29
|
+
export const REGISTRATION_PUBLIC_KEY = Buffer.from([
|
|
30
|
+
5, 142, 140, 15, 116, 195, 235, 197, 215, 166, 134, 92, 108, 60, 132, 56, 86, 176, 97, 33, 204, 232, 234, 119, 77,
|
|
31
|
+
34, 251, 111, 18, 37, 18, 48, 45,
|
|
32
|
+
])
|
|
33
|
+
export const NOISE_MODE = 'Noise_XX_25519_AESGCM_SHA256\0\0\0\0'
|
|
34
|
+
export const DICT_VERSION = 2
|
|
35
|
+
export const KEY_BUNDLE_TYPE = Buffer.from([5])
|
|
36
|
+
export const NOISE_WA_HEADER = Buffer.from(
|
|
37
|
+
[ 87, 65, 6, DICT_VERSION ]
|
|
38
|
+
) // last is "DICT_VERSION"
|
|
39
|
+
export const PROTOCOL_VERSION = [5, 2]
|
|
40
|
+
export const MOBILE_NOISE_HEADER = Buffer.concat([Buffer.from('WA'), Buffer.from(PROTOCOL_VERSION)])
|
|
41
|
+
/** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
|
|
42
|
+
export const URL_REGEX = /(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/
|
|
43
|
+
|
|
44
|
+
export const WA_CERT_DETAILS = {
|
|
45
|
+
SERIAL: 0,
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const PROCESSABLE_HISTORY_TYPES = [
|
|
49
|
+
proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_BOOTSTRAP,
|
|
50
|
+
proto.Message.HistorySyncNotification.HistorySyncType.PUSH_NAME,
|
|
51
|
+
proto.Message.HistorySyncNotification.HistorySyncType.RECENT,
|
|
52
|
+
proto.Message.HistorySyncNotification.HistorySyncType.FULL
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
export const DEFAULT_CONNECTION_CONFIG: SocketConfig = {
|
|
56
|
+
version: version as WAVersion,
|
|
57
|
+
browser: Browsers.ubuntu('Chrome'),
|
|
58
|
+
waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
|
|
59
|
+
connectTimeoutMs: 20_000,
|
|
60
|
+
keepAliveIntervalMs: 30_000,
|
|
61
|
+
logger: logger.child({ class: 'baileys' }),
|
|
62
|
+
printQRInTerminal: false,
|
|
63
|
+
emitOwnEvents: true,
|
|
64
|
+
defaultQueryTimeoutMs: 60_000,
|
|
65
|
+
customUploadHosts: [],
|
|
66
|
+
retryRequestDelayMs: 250,
|
|
67
|
+
maxMsgRetryCount: 5,
|
|
68
|
+
fireInitQueries: true,
|
|
69
|
+
auth: undefined as unknown as AuthenticationState,
|
|
70
|
+
markOnlineOnConnect: true,
|
|
71
|
+
syncFullHistory: false,
|
|
72
|
+
patchMessageBeforeSending: msg => msg,
|
|
73
|
+
shouldSyncHistoryMessage: () => true,
|
|
74
|
+
shouldIgnoreJid: () => false,
|
|
75
|
+
linkPreviewImageThumbnailWidth: 192,
|
|
76
|
+
transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
|
|
77
|
+
generateHighQualityLinkPreview: false,
|
|
78
|
+
options: { },
|
|
79
|
+
appStateMacVerification: {
|
|
80
|
+
patch: false,
|
|
81
|
+
snapshot: false,
|
|
82
|
+
},
|
|
83
|
+
getMessage: async() => undefined,
|
|
84
|
+
makeSignalRepository: makeLibSignalRepository
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export const MEDIA_PATH_MAP: { [T in MediaType]?: string } = {
|
|
88
|
+
image: '/mms/image',
|
|
89
|
+
video: '/mms/video',
|
|
90
|
+
document: '/mms/document',
|
|
91
|
+
audio: '/mms/audio',
|
|
92
|
+
sticker: '/mms/image',
|
|
93
|
+
'thumbnail-link': '/mms/image',
|
|
94
|
+
'product-catalog-image': '/product/image',
|
|
95
|
+
'md-app-state': '',
|
|
96
|
+
'md-msg-hist': '/mms/md-app-state',
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export const MEDIA_HKDF_KEY_MAPPING = {
|
|
100
|
+
'audio': 'Audio',
|
|
101
|
+
'document': 'Document',
|
|
102
|
+
'gif': 'Video',
|
|
103
|
+
'image': 'Image',
|
|
104
|
+
'ppic': '',
|
|
105
|
+
'product': 'Image',
|
|
106
|
+
'ptt': 'Audio',
|
|
107
|
+
'sticker': 'Image',
|
|
108
|
+
'video': 'Video',
|
|
109
|
+
'thumbnail-document': 'Document Thumbnail',
|
|
110
|
+
'thumbnail-image': 'Image Thumbnail',
|
|
111
|
+
'thumbnail-video': 'Video Thumbnail',
|
|
112
|
+
'thumbnail-link': 'Link Thumbnail',
|
|
113
|
+
'md-msg-hist': 'History',
|
|
114
|
+
'md-app-state': 'App State',
|
|
115
|
+
'product-catalog-image': '',
|
|
116
|
+
'payment-bg-image': 'Payment Background',
|
|
117
|
+
'ptv': 'Video'
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export const MEDIA_KEYS = Object.keys(MEDIA_PATH_MAP) as MediaType[]
|
|
121
|
+
|
|
122
|
+
export const MIN_PREKEY_COUNT = 5
|
|
123
|
+
|
|
124
|
+
export const INITIAL_PREKEY_COUNT = 30
|
|
125
|
+
|
|
126
|
+
export const DEFAULT_CACHE_TTLS = {
|
|
127
|
+
SIGNAL_STORE: 5 * 60, // 5 minutes
|
|
128
|
+
MSG_RETRY: 60 * 60, // 1 hour
|
|
129
|
+
CALL_OFFER: 5 * 60, // 5 minutes
|
|
130
|
+
USER_DEVICES: 5 * 60, // 5 minutes
|
|
131
|
+
}
|
|
@@ -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,180 @@
|
|
|
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
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.makeLibSignalRepository = makeLibSignalRepository;
|
|
46
|
+
const libsignal = __importStar(require("libsignal"));
|
|
47
|
+
const WASignalGroup_1 = require("../../WASignalGroup");
|
|
48
|
+
const Utils_1 = require("../Utils");
|
|
49
|
+
const WABinary_1 = require("../WABinary");
|
|
50
|
+
function makeLibSignalRepository(auth) {
|
|
51
|
+
const storage = signalStorage(auth);
|
|
52
|
+
return {
|
|
53
|
+
decryptGroupMessage({ group, authorJid, msg }) {
|
|
54
|
+
const senderName = jidToSignalSenderKeyName(group, authorJid);
|
|
55
|
+
const cipher = new WASignalGroup_1.GroupCipher(storage, senderName);
|
|
56
|
+
return cipher.decrypt(msg);
|
|
57
|
+
},
|
|
58
|
+
processSenderKeyDistributionMessage(_a) {
|
|
59
|
+
return __awaiter(this, arguments, void 0, function* ({ item, authorJid }) {
|
|
60
|
+
const builder = new WASignalGroup_1.GroupSessionBuilder(storage);
|
|
61
|
+
const senderName = jidToSignalSenderKeyName(item.groupId, authorJid);
|
|
62
|
+
const senderMsg = new WASignalGroup_1.SenderKeyDistributionMessage(null, null, null, null, item.axolotlSenderKeyDistributionMessage);
|
|
63
|
+
const { [senderName]: senderKey } = yield auth.keys.get('sender-key', [senderName]);
|
|
64
|
+
if (!senderKey) {
|
|
65
|
+
yield storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord());
|
|
66
|
+
}
|
|
67
|
+
yield builder.process(senderName, senderMsg);
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
decryptMessage(_a) {
|
|
71
|
+
return __awaiter(this, arguments, void 0, function* ({ jid, type, ciphertext }) {
|
|
72
|
+
const addr = jidToSignalProtocolAddress(jid);
|
|
73
|
+
const session = new libsignal.SessionCipher(storage, addr);
|
|
74
|
+
let result;
|
|
75
|
+
switch (type) {
|
|
76
|
+
case 'pkmsg':
|
|
77
|
+
result = yield session.decryptPreKeyWhisperMessage(ciphertext);
|
|
78
|
+
break;
|
|
79
|
+
case 'msg':
|
|
80
|
+
result = yield session.decryptWhisperMessage(ciphertext);
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
encryptMessage(_a) {
|
|
87
|
+
return __awaiter(this, arguments, void 0, function* ({ jid, data }) {
|
|
88
|
+
const addr = jidToSignalProtocolAddress(jid);
|
|
89
|
+
const cipher = new libsignal.SessionCipher(storage, addr);
|
|
90
|
+
const { type: sigType, body } = yield cipher.encrypt(data);
|
|
91
|
+
const type = sigType === 3 ? 'pkmsg' : 'msg';
|
|
92
|
+
return { type, ciphertext: Buffer.from(body, 'binary') };
|
|
93
|
+
});
|
|
94
|
+
},
|
|
95
|
+
encryptGroupMessage(_a) {
|
|
96
|
+
return __awaiter(this, arguments, void 0, function* ({ group, meId, data }) {
|
|
97
|
+
const senderName = jidToSignalSenderKeyName(group, meId);
|
|
98
|
+
const builder = new WASignalGroup_1.GroupSessionBuilder(storage);
|
|
99
|
+
const { [senderName]: senderKey } = yield auth.keys.get('sender-key', [senderName]);
|
|
100
|
+
if (!senderKey) {
|
|
101
|
+
yield storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord());
|
|
102
|
+
}
|
|
103
|
+
const senderKeyDistributionMessage = yield builder.create(senderName);
|
|
104
|
+
const session = new WASignalGroup_1.GroupCipher(storage, senderName);
|
|
105
|
+
const ciphertext = yield session.encrypt(data);
|
|
106
|
+
return {
|
|
107
|
+
ciphertext,
|
|
108
|
+
senderKeyDistributionMessage: senderKeyDistributionMessage.serialize(),
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
injectE2ESession(_a) {
|
|
113
|
+
return __awaiter(this, arguments, void 0, function* ({ jid, session }) {
|
|
114
|
+
const cipher = new libsignal.SessionBuilder(storage, jidToSignalProtocolAddress(jid));
|
|
115
|
+
yield cipher.initOutgoing(session);
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
jidToSignalProtocolAddress(jid) {
|
|
119
|
+
return jidToSignalProtocolAddress(jid).toString();
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
const jidToSignalProtocolAddress = (jid) => {
|
|
124
|
+
const { user, device } = (0, WABinary_1.jidDecode)(jid);
|
|
125
|
+
return new libsignal.ProtocolAddress(user, device || 0);
|
|
126
|
+
};
|
|
127
|
+
const jidToSignalSenderKeyName = (group, user) => {
|
|
128
|
+
return new WASignalGroup_1.SenderKeyName(group, jidToSignalProtocolAddress(user)).toString();
|
|
129
|
+
};
|
|
130
|
+
function signalStorage({ creds, keys }) {
|
|
131
|
+
return {
|
|
132
|
+
loadSession: (id) => __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
const { [id]: sess } = yield keys.get('session', [id]);
|
|
134
|
+
if (sess) {
|
|
135
|
+
return libsignal.SessionRecord.deserialize(sess);
|
|
136
|
+
}
|
|
137
|
+
}),
|
|
138
|
+
storeSession: (id, session) => __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
yield keys.set({ 'session': { [id]: session.serialize() } });
|
|
140
|
+
}),
|
|
141
|
+
isTrustedIdentity: () => {
|
|
142
|
+
return true;
|
|
143
|
+
},
|
|
144
|
+
loadPreKey: (id) => __awaiter(this, void 0, void 0, function* () {
|
|
145
|
+
const keyId = id.toString();
|
|
146
|
+
const { [keyId]: key } = yield keys.get('pre-key', [keyId]);
|
|
147
|
+
if (key) {
|
|
148
|
+
return {
|
|
149
|
+
privKey: Buffer.from(key.private),
|
|
150
|
+
pubKey: Buffer.from(key.public)
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}),
|
|
154
|
+
removePreKey: (id) => keys.set({ 'pre-key': { [id]: null } }),
|
|
155
|
+
loadSignedPreKey: () => {
|
|
156
|
+
const key = creds.signedPreKey;
|
|
157
|
+
return {
|
|
158
|
+
privKey: Buffer.from(key.keyPair.private),
|
|
159
|
+
pubKey: Buffer.from(key.keyPair.public)
|
|
160
|
+
};
|
|
161
|
+
},
|
|
162
|
+
loadSenderKey: (keyId) => __awaiter(this, void 0, void 0, function* () {
|
|
163
|
+
const { [keyId]: key } = yield keys.get('sender-key', [keyId]);
|
|
164
|
+
if (key) {
|
|
165
|
+
return new WASignalGroup_1.SenderKeyRecord(key);
|
|
166
|
+
}
|
|
167
|
+
}),
|
|
168
|
+
storeSenderKey: (keyId, key) => __awaiter(this, void 0, void 0, function* () {
|
|
169
|
+
yield keys.set({ 'sender-key': { [keyId]: key.serialize() } });
|
|
170
|
+
}),
|
|
171
|
+
getOurRegistrationId: () => (creds.registrationId),
|
|
172
|
+
getOurIdentity: () => {
|
|
173
|
+
const { signedIdentityKey } = creds;
|
|
174
|
+
return {
|
|
175
|
+
privKey: Buffer.from(signedIdentityKey.private),
|
|
176
|
+
pubKey: (0, Utils_1.generateSignalPubKey)(signedIdentityKey.public),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
}
|