@inline-chat/hermes-agent-adapter 0.0.17 → 0.0.18
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/README.md +11 -7
- package/dist/install.js +100 -82
- package/package.json +7 -7
- package/plugin/inline/adapter.py +12 -14
- package/plugin/inline/cli.py +48 -3
- package/plugin/inline/plugin.yaml +4 -1
- package/plugin/inline/sidecar/index.mjs +83 -1743
|
@@ -4,22 +4,38 @@ var __getProtoOf = Object.getPrototypeOf;
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
function __accessProp(key) {
|
|
8
|
+
return this[key];
|
|
9
|
+
}
|
|
10
|
+
var __toESMCache_node;
|
|
11
|
+
var __toESMCache_esm;
|
|
7
12
|
var __toESM = (mod, isNodeMode, target) => {
|
|
13
|
+
var canCache = mod != null && typeof mod === "object";
|
|
14
|
+
if (canCache) {
|
|
15
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
16
|
+
var cached = cache.get(mod);
|
|
17
|
+
if (cached)
|
|
18
|
+
return cached;
|
|
19
|
+
}
|
|
8
20
|
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
21
|
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
22
|
+
if (mod && typeof mod === "object" || typeof mod === "function") {
|
|
23
|
+
for (let key of __getOwnPropNames(mod))
|
|
24
|
+
if (!__hasOwnProp.call(to, key))
|
|
25
|
+
__defProp(to, key, {
|
|
26
|
+
get: __accessProp.bind(mod, key),
|
|
27
|
+
enumerable: true
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (canCache)
|
|
31
|
+
cache.set(mod, to);
|
|
16
32
|
return to;
|
|
17
33
|
};
|
|
18
34
|
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
19
35
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
20
36
|
|
|
21
37
|
// node_modules/@protobuf-ts/runtime/build/commonjs/json-typings.js
|
|
22
|
-
var require_json_typings = __commonJS((exports)
|
|
38
|
+
var require_json_typings = __commonJS(function(exports) {
|
|
23
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
40
|
exports.isJsonObject = exports.typeofJsonValue = undefined;
|
|
25
41
|
function typeofJsonValue(value) {
|
|
@@ -40,7 +56,7 @@ var require_json_typings = __commonJS((exports) => {
|
|
|
40
56
|
});
|
|
41
57
|
|
|
42
58
|
// node_modules/@protobuf-ts/runtime/build/commonjs/base64.js
|
|
43
|
-
var require_base64 = __commonJS((exports)
|
|
59
|
+
var require_base64 = __commonJS(function(exports) {
|
|
44
60
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
61
|
exports.base64encode = exports.base64decode = undefined;
|
|
46
62
|
var encTable = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
|
|
@@ -132,7 +148,7 @@ var require_base64 = __commonJS((exports) => {
|
|
|
132
148
|
});
|
|
133
149
|
|
|
134
150
|
// node_modules/@protobuf-ts/runtime/build/commonjs/protobufjs-utf8.js
|
|
135
|
-
var require_protobufjs_utf8 = __commonJS((exports)
|
|
151
|
+
var require_protobufjs_utf8 = __commonJS(function(exports) {
|
|
136
152
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
137
153
|
exports.utf8read = undefined;
|
|
138
154
|
var fromCharCodes = (chunk) => String.fromCharCode.apply(String, chunk);
|
|
@@ -169,7 +185,7 @@ var require_protobufjs_utf8 = __commonJS((exports) => {
|
|
|
169
185
|
});
|
|
170
186
|
|
|
171
187
|
// node_modules/@protobuf-ts/runtime/build/commonjs/binary-format-contract.js
|
|
172
|
-
var require_binary_format_contract = __commonJS((exports)
|
|
188
|
+
var require_binary_format_contract = __commonJS(function(exports) {
|
|
173
189
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
174
190
|
exports.WireType = exports.mergeBinaryOptions = exports.UnknownFieldHandler = undefined;
|
|
175
191
|
var UnknownFieldHandler;
|
|
@@ -209,7 +225,7 @@ var require_binary_format_contract = __commonJS((exports) => {
|
|
|
209
225
|
});
|
|
210
226
|
|
|
211
227
|
// node_modules/@protobuf-ts/runtime/build/commonjs/goog-varint.js
|
|
212
|
-
var require_goog_varint = __commonJS((exports)
|
|
228
|
+
var require_goog_varint = __commonJS(function(exports) {
|
|
213
229
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
214
230
|
exports.varint32read = exports.varint32write = exports.int64toString = exports.int64fromString = exports.varint64write = exports.varint64read = undefined;
|
|
215
231
|
function varint64read() {
|
|
@@ -376,7 +392,7 @@ var require_goog_varint = __commonJS((exports) => {
|
|
|
376
392
|
});
|
|
377
393
|
|
|
378
394
|
// node_modules/@protobuf-ts/runtime/build/commonjs/pb-long.js
|
|
379
|
-
var require_pb_long = __commonJS((exports)
|
|
395
|
+
var require_pb_long = __commonJS(function(exports) {
|
|
380
396
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
381
397
|
exports.PbLong = exports.PbULong = exports.detectBi = undefined;
|
|
382
398
|
var goog_varint_1 = require_goog_varint();
|
|
@@ -560,7 +576,7 @@ var require_pb_long = __commonJS((exports) => {
|
|
|
560
576
|
});
|
|
561
577
|
|
|
562
578
|
// node_modules/@protobuf-ts/runtime/build/commonjs/binary-reader.js
|
|
563
|
-
var require_binary_reader = __commonJS((exports)
|
|
579
|
+
var require_binary_reader = __commonJS(function(exports) {
|
|
564
580
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
565
581
|
exports.BinaryReader = exports.binaryReadOptions = undefined;
|
|
566
582
|
var binary_format_contract_1 = require_binary_format_contract();
|
|
@@ -682,7 +698,7 @@ var require_binary_reader = __commonJS((exports) => {
|
|
|
682
698
|
});
|
|
683
699
|
|
|
684
700
|
// node_modules/@protobuf-ts/runtime/build/commonjs/assert.js
|
|
685
|
-
var require_assert = __commonJS((exports)
|
|
701
|
+
var require_assert = __commonJS(function(exports) {
|
|
686
702
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
687
703
|
exports.assertFloat32 = exports.assertUInt32 = exports.assertInt32 = exports.assertNever = exports.assert = undefined;
|
|
688
704
|
function assert(condition, msg) {
|
|
@@ -726,7 +742,7 @@ var require_assert = __commonJS((exports) => {
|
|
|
726
742
|
});
|
|
727
743
|
|
|
728
744
|
// node_modules/@protobuf-ts/runtime/build/commonjs/binary-writer.js
|
|
729
|
-
var require_binary_writer = __commonJS((exports)
|
|
745
|
+
var require_binary_writer = __commonJS(function(exports) {
|
|
730
746
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
731
747
|
exports.BinaryWriter = exports.binaryWriteOptions = undefined;
|
|
732
748
|
var pb_long_1 = require_pb_long();
|
|
@@ -881,7 +897,7 @@ var require_binary_writer = __commonJS((exports) => {
|
|
|
881
897
|
});
|
|
882
898
|
|
|
883
899
|
// node_modules/@protobuf-ts/runtime/build/commonjs/json-format-contract.js
|
|
884
|
-
var require_json_format_contract = __commonJS((exports)
|
|
900
|
+
var require_json_format_contract = __commonJS(function(exports) {
|
|
885
901
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
886
902
|
exports.mergeJsonOptions = exports.jsonWriteOptions = exports.jsonReadOptions = undefined;
|
|
887
903
|
var defaultsWrite = {
|
|
@@ -911,14 +927,14 @@ var require_json_format_contract = __commonJS((exports) => {
|
|
|
911
927
|
});
|
|
912
928
|
|
|
913
929
|
// node_modules/@protobuf-ts/runtime/build/commonjs/message-type-contract.js
|
|
914
|
-
var require_message_type_contract = __commonJS((exports)
|
|
930
|
+
var require_message_type_contract = __commonJS(function(exports) {
|
|
915
931
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
916
932
|
exports.MESSAGE_TYPE = undefined;
|
|
917
933
|
exports.MESSAGE_TYPE = Symbol.for("protobuf-ts/message-type");
|
|
918
934
|
});
|
|
919
935
|
|
|
920
936
|
// node_modules/@protobuf-ts/runtime/build/commonjs/lower-camel-case.js
|
|
921
|
-
var require_lower_camel_case = __commonJS((exports)
|
|
937
|
+
var require_lower_camel_case = __commonJS(function(exports) {
|
|
922
938
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
923
939
|
exports.lowerCamelCase = undefined;
|
|
924
940
|
function lowerCamelCase(snakeCase) {
|
|
@@ -946,7 +962,7 @@ var require_lower_camel_case = __commonJS((exports) => {
|
|
|
946
962
|
});
|
|
947
963
|
|
|
948
964
|
// node_modules/@protobuf-ts/runtime/build/commonjs/reflection-info.js
|
|
949
|
-
var require_reflection_info = __commonJS((exports)
|
|
965
|
+
var require_reflection_info = __commonJS(function(exports) {
|
|
950
966
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
951
967
|
exports.readMessageOption = exports.readFieldOption = exports.readFieldOptions = exports.normalizeFieldInfo = exports.RepeatType = exports.LongType = exports.ScalarType = undefined;
|
|
952
968
|
var lower_camel_case_1 = require_lower_camel_case();
|
|
@@ -1020,7 +1036,7 @@ var require_reflection_info = __commonJS((exports) => {
|
|
|
1020
1036
|
});
|
|
1021
1037
|
|
|
1022
1038
|
// node_modules/@protobuf-ts/runtime/build/commonjs/oneof.js
|
|
1023
|
-
var require_oneof = __commonJS((exports)
|
|
1039
|
+
var require_oneof = __commonJS(function(exports) {
|
|
1024
1040
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1025
1041
|
exports.getSelectedOneofValue = exports.clearOneofValue = exports.setUnknownOneofValue = exports.setOneofValue = exports.getOneofValue = exports.isOneofGroup = undefined;
|
|
1026
1042
|
function isOneofGroup(any) {
|
|
@@ -1080,7 +1096,7 @@ var require_oneof = __commonJS((exports) => {
|
|
|
1080
1096
|
});
|
|
1081
1097
|
|
|
1082
1098
|
// node_modules/@protobuf-ts/runtime/build/commonjs/reflection-type-check.js
|
|
1083
|
-
var require_reflection_type_check = __commonJS((exports)
|
|
1099
|
+
var require_reflection_type_check = __commonJS(function(exports) {
|
|
1084
1100
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1085
1101
|
exports.ReflectionTypeCheck = undefined;
|
|
1086
1102
|
var reflection_info_1 = require_reflection_info();
|
|
@@ -1281,7 +1297,7 @@ var require_reflection_type_check = __commonJS((exports) => {
|
|
|
1281
1297
|
});
|
|
1282
1298
|
|
|
1283
1299
|
// node_modules/@protobuf-ts/runtime/build/commonjs/reflection-long-convert.js
|
|
1284
|
-
var require_reflection_long_convert = __commonJS((exports)
|
|
1300
|
+
var require_reflection_long_convert = __commonJS(function(exports) {
|
|
1285
1301
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1286
1302
|
exports.reflectionLongConvert = undefined;
|
|
1287
1303
|
var reflection_info_1 = require_reflection_info();
|
|
@@ -1299,7 +1315,7 @@ var require_reflection_long_convert = __commonJS((exports) => {
|
|
|
1299
1315
|
});
|
|
1300
1316
|
|
|
1301
1317
|
// node_modules/@protobuf-ts/runtime/build/commonjs/reflection-json-reader.js
|
|
1302
|
-
var require_reflection_json_reader = __commonJS((exports)
|
|
1318
|
+
var require_reflection_json_reader = __commonJS(function(exports) {
|
|
1303
1319
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1304
1320
|
exports.ReflectionJsonReader = undefined;
|
|
1305
1321
|
var json_typings_1 = require_json_typings();
|
|
@@ -1573,7 +1589,7 @@ var require_reflection_json_reader = __commonJS((exports) => {
|
|
|
1573
1589
|
});
|
|
1574
1590
|
|
|
1575
1591
|
// node_modules/@protobuf-ts/runtime/build/commonjs/reflection-json-writer.js
|
|
1576
|
-
var require_reflection_json_writer = __commonJS((exports)
|
|
1592
|
+
var require_reflection_json_writer = __commonJS(function(exports) {
|
|
1577
1593
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1578
1594
|
exports.ReflectionJsonWriter = undefined;
|
|
1579
1595
|
var base64_1 = require_base64();
|
|
@@ -1776,7 +1792,7 @@ var require_reflection_json_writer = __commonJS((exports) => {
|
|
|
1776
1792
|
});
|
|
1777
1793
|
|
|
1778
1794
|
// node_modules/@protobuf-ts/runtime/build/commonjs/reflection-scalar-default.js
|
|
1779
|
-
var require_reflection_scalar_default = __commonJS((exports)
|
|
1795
|
+
var require_reflection_scalar_default = __commonJS(function(exports) {
|
|
1780
1796
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1781
1797
|
exports.reflectionScalarDefault = undefined;
|
|
1782
1798
|
var reflection_info_1 = require_reflection_info();
|
|
@@ -1808,7 +1824,7 @@ var require_reflection_scalar_default = __commonJS((exports) => {
|
|
|
1808
1824
|
});
|
|
1809
1825
|
|
|
1810
1826
|
// node_modules/@protobuf-ts/runtime/build/commonjs/reflection-binary-reader.js
|
|
1811
|
-
var require_reflection_binary_reader = __commonJS((exports)
|
|
1827
|
+
var require_reflection_binary_reader = __commonJS(function(exports) {
|
|
1812
1828
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1813
1829
|
exports.ReflectionBinaryReader = undefined;
|
|
1814
1830
|
var binary_format_contract_1 = require_binary_format_contract();
|
|
@@ -1968,7 +1984,7 @@ var require_reflection_binary_reader = __commonJS((exports) => {
|
|
|
1968
1984
|
});
|
|
1969
1985
|
|
|
1970
1986
|
// node_modules/@protobuf-ts/runtime/build/commonjs/reflection-binary-writer.js
|
|
1971
|
-
var require_reflection_binary_writer = __commonJS((exports)
|
|
1987
|
+
var require_reflection_binary_writer = __commonJS(function(exports) {
|
|
1972
1988
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1973
1989
|
exports.ReflectionBinaryWriter = undefined;
|
|
1974
1990
|
var binary_format_contract_1 = require_binary_format_contract();
|
|
@@ -2166,7 +2182,7 @@ var require_reflection_binary_writer = __commonJS((exports) => {
|
|
|
2166
2182
|
});
|
|
2167
2183
|
|
|
2168
2184
|
// node_modules/@protobuf-ts/runtime/build/commonjs/reflection-create.js
|
|
2169
|
-
var require_reflection_create = __commonJS((exports)
|
|
2185
|
+
var require_reflection_create = __commonJS(function(exports) {
|
|
2170
2186
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2171
2187
|
exports.reflectionCreate = undefined;
|
|
2172
2188
|
var reflection_scalar_default_1 = require_reflection_scalar_default();
|
|
@@ -2200,7 +2216,7 @@ var require_reflection_create = __commonJS((exports) => {
|
|
|
2200
2216
|
});
|
|
2201
2217
|
|
|
2202
2218
|
// node_modules/@protobuf-ts/runtime/build/commonjs/reflection-merge-partial.js
|
|
2203
|
-
var require_reflection_merge_partial = __commonJS((exports)
|
|
2219
|
+
var require_reflection_merge_partial = __commonJS(function(exports) {
|
|
2204
2220
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2205
2221
|
exports.reflectionMergePartial = undefined;
|
|
2206
2222
|
function reflectionMergePartial(info, target, source) {
|
|
@@ -2267,7 +2283,7 @@ var require_reflection_merge_partial = __commonJS((exports) => {
|
|
|
2267
2283
|
});
|
|
2268
2284
|
|
|
2269
2285
|
// node_modules/@protobuf-ts/runtime/build/commonjs/reflection-equals.js
|
|
2270
|
-
var require_reflection_equals = __commonJS((exports)
|
|
2286
|
+
var require_reflection_equals = __commonJS(function(exports) {
|
|
2271
2287
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2272
2288
|
exports.reflectionEquals = undefined;
|
|
2273
2289
|
var reflection_info_1 = require_reflection_info();
|
|
@@ -2335,7 +2351,7 @@ var require_reflection_equals = __commonJS((exports) => {
|
|
|
2335
2351
|
});
|
|
2336
2352
|
|
|
2337
2353
|
// node_modules/@protobuf-ts/runtime/build/commonjs/message-type.js
|
|
2338
|
-
var require_message_type = __commonJS((exports)
|
|
2354
|
+
var require_message_type = __commonJS(function(exports) {
|
|
2339
2355
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2340
2356
|
exports.MessageType = undefined;
|
|
2341
2357
|
var message_type_contract_1 = require_message_type_contract();
|
|
@@ -2441,7 +2457,7 @@ var require_message_type = __commonJS((exports) => {
|
|
|
2441
2457
|
});
|
|
2442
2458
|
|
|
2443
2459
|
// node_modules/@protobuf-ts/runtime/build/commonjs/reflection-contains-message-type.js
|
|
2444
|
-
var require_reflection_contains_message_type = __commonJS((exports)
|
|
2460
|
+
var require_reflection_contains_message_type = __commonJS(function(exports) {
|
|
2445
2461
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2446
2462
|
exports.containsMessageType = undefined;
|
|
2447
2463
|
var message_type_contract_1 = require_message_type_contract();
|
|
@@ -2452,7 +2468,7 @@ var require_reflection_contains_message_type = __commonJS((exports) => {
|
|
|
2452
2468
|
});
|
|
2453
2469
|
|
|
2454
2470
|
// node_modules/@protobuf-ts/runtime/build/commonjs/enum-object.js
|
|
2455
|
-
var require_enum_object = __commonJS((exports)
|
|
2471
|
+
var require_enum_object = __commonJS(function(exports) {
|
|
2456
2472
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2457
2473
|
exports.listEnumNumbers = exports.listEnumNames = exports.listEnumValues = exports.isEnumObject = undefined;
|
|
2458
2474
|
function isEnumObject(arg) {
|
|
@@ -2504,7 +2520,7 @@ var require_enum_object = __commonJS((exports) => {
|
|
|
2504
2520
|
});
|
|
2505
2521
|
|
|
2506
2522
|
// node_modules/@protobuf-ts/runtime/build/commonjs/index.js
|
|
2507
|
-
var require_commonjs = __commonJS((exports)
|
|
2523
|
+
var require_commonjs = __commonJS(function(exports) {
|
|
2508
2524
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2509
2525
|
var json_typings_1 = require_json_typings();
|
|
2510
2526
|
Object.defineProperty(exports, "typeofJsonValue", { enumerable: true, get: function() {
|
|
@@ -2687,7 +2703,7 @@ var require_commonjs = __commonJS((exports) => {
|
|
|
2687
2703
|
});
|
|
2688
2704
|
|
|
2689
2705
|
// node_modules/ws/lib/constants.js
|
|
2690
|
-
var require_constants = __commonJS((exports, module)
|
|
2706
|
+
var require_constants = __commonJS(function(exports, module) {
|
|
2691
2707
|
var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
|
|
2692
2708
|
var hasBlob = typeof Blob !== "undefined";
|
|
2693
2709
|
if (hasBlob)
|
|
@@ -2707,7 +2723,7 @@ var require_constants = __commonJS((exports, module) => {
|
|
|
2707
2723
|
});
|
|
2708
2724
|
|
|
2709
2725
|
// node_modules/ws/lib/buffer-util.js
|
|
2710
|
-
var require_buffer_util = __commonJS((exports, module)
|
|
2726
|
+
var require_buffer_util = __commonJS(function(exports, module) {
|
|
2711
2727
|
var { EMPTY_BUFFER } = require_constants();
|
|
2712
2728
|
var FastBuffer = Buffer[Symbol.species];
|
|
2713
2729
|
function concat(list, totalLength) {
|
|
@@ -2785,7 +2801,7 @@ var require_buffer_util = __commonJS((exports, module) => {
|
|
|
2785
2801
|
});
|
|
2786
2802
|
|
|
2787
2803
|
// node_modules/ws/lib/limiter.js
|
|
2788
|
-
var require_limiter = __commonJS((exports, module)
|
|
2804
|
+
var require_limiter = __commonJS(function(exports, module) {
|
|
2789
2805
|
var kDone = Symbol("kDone");
|
|
2790
2806
|
var kRun = Symbol("kRun");
|
|
2791
2807
|
|
|
@@ -2817,7 +2833,7 @@ var require_limiter = __commonJS((exports, module) => {
|
|
|
2817
2833
|
});
|
|
2818
2834
|
|
|
2819
2835
|
// node_modules/ws/lib/permessage-deflate.js
|
|
2820
|
-
var require_permessage_deflate = __commonJS((exports, module)
|
|
2836
|
+
var require_permessage_deflate = __commonJS(function(exports, module) {
|
|
2821
2837
|
var zlib = __require("zlib");
|
|
2822
2838
|
var bufferUtil = require_buffer_util();
|
|
2823
2839
|
var Limiter = require_limiter();
|
|
@@ -3081,7 +3097,7 @@ var require_permessage_deflate = __commonJS((exports, module) => {
|
|
|
3081
3097
|
});
|
|
3082
3098
|
|
|
3083
3099
|
// node_modules/ws/lib/validation.js
|
|
3084
|
-
var require_validation = __commonJS((exports, module)
|
|
3100
|
+
var require_validation = __commonJS(function(exports, module) {
|
|
3085
3101
|
var { isUtf8 } = __require("buffer");
|
|
3086
3102
|
var { hasBlob } = require_constants();
|
|
3087
3103
|
var tokenChars = [
|
|
@@ -3268,7 +3284,7 @@ var require_validation = __commonJS((exports, module) => {
|
|
|
3268
3284
|
});
|
|
3269
3285
|
|
|
3270
3286
|
// node_modules/ws/lib/receiver.js
|
|
3271
|
-
var require_receiver = __commonJS((exports, module)
|
|
3287
|
+
var require_receiver = __commonJS(function(exports, module) {
|
|
3272
3288
|
var { Writable } = __require("stream");
|
|
3273
3289
|
var PerMessageDeflate = require_permessage_deflate();
|
|
3274
3290
|
var {
|
|
@@ -3662,7 +3678,7 @@ var require_receiver = __commonJS((exports, module) => {
|
|
|
3662
3678
|
});
|
|
3663
3679
|
|
|
3664
3680
|
// node_modules/ws/lib/sender.js
|
|
3665
|
-
var require_sender = __commonJS((exports, module)
|
|
3681
|
+
var require_sender = __commonJS(function(exports, module) {
|
|
3666
3682
|
var { Duplex } = __require("stream");
|
|
3667
3683
|
var { randomFillSync } = __require("crypto");
|
|
3668
3684
|
var {
|
|
@@ -4021,7 +4037,7 @@ var require_sender = __commonJS((exports, module) => {
|
|
|
4021
4037
|
});
|
|
4022
4038
|
|
|
4023
4039
|
// node_modules/ws/lib/event-target.js
|
|
4024
|
-
var require_event_target = __commonJS((exports, module)
|
|
4040
|
+
var require_event_target = __commonJS(function(exports, module) {
|
|
4025
4041
|
var { kForOnEventAttribute, kListener } = require_constants();
|
|
4026
4042
|
var kCode = Symbol("kCode");
|
|
4027
4043
|
var kData = Symbol("kData");
|
|
@@ -4172,7 +4188,7 @@ var require_event_target = __commonJS((exports, module) => {
|
|
|
4172
4188
|
});
|
|
4173
4189
|
|
|
4174
4190
|
// node_modules/ws/lib/extension.js
|
|
4175
|
-
var require_extension = __commonJS((exports, module)
|
|
4191
|
+
var require_extension = __commonJS(function(exports, module) {
|
|
4176
4192
|
var { tokenChars } = require_validation();
|
|
4177
4193
|
function push(dest, name, elem) {
|
|
4178
4194
|
if (dest[name] === undefined)
|
|
@@ -4337,7 +4353,7 @@ var require_extension = __commonJS((exports, module) => {
|
|
|
4337
4353
|
});
|
|
4338
4354
|
|
|
4339
4355
|
// node_modules/ws/lib/websocket.js
|
|
4340
|
-
var require_websocket = __commonJS((exports, module)
|
|
4356
|
+
var require_websocket = __commonJS(function(exports, module) {
|
|
4341
4357
|
var EventEmitter = __require("events");
|
|
4342
4358
|
var https = __require("https");
|
|
4343
4359
|
var http = __require("http");
|
|
@@ -4393,11 +4409,23 @@ var require_websocket = __commonJS((exports, module) => {
|
|
|
4393
4409
|
this._isServer = false;
|
|
4394
4410
|
this._redirects = 0;
|
|
4395
4411
|
if (protocols === undefined) {
|
|
4396
|
-
protocols
|
|
4412
|
+
if (!options || options.protocols === undefined) {
|
|
4413
|
+
protocols = [];
|
|
4414
|
+
} else if (Array.isArray(options.protocols)) {
|
|
4415
|
+
protocols = options.protocols;
|
|
4416
|
+
} else {
|
|
4417
|
+
protocols = [options.protocols];
|
|
4418
|
+
}
|
|
4397
4419
|
} else if (!Array.isArray(protocols)) {
|
|
4398
4420
|
if (typeof protocols === "object" && protocols !== null) {
|
|
4399
4421
|
options = protocols;
|
|
4400
|
-
protocols
|
|
4422
|
+
if (options.protocols === undefined) {
|
|
4423
|
+
protocols = [];
|
|
4424
|
+
} else if (Array.isArray(options.protocols)) {
|
|
4425
|
+
protocols = options.protocols;
|
|
4426
|
+
} else {
|
|
4427
|
+
protocols = [options.protocols];
|
|
4428
|
+
}
|
|
4401
4429
|
} else {
|
|
4402
4430
|
protocols = [protocols];
|
|
4403
4431
|
}
|
|
@@ -4516,7 +4544,6 @@ var require_websocket = __commonJS((exports, module) => {
|
|
|
4516
4544
|
}
|
|
4517
4545
|
return;
|
|
4518
4546
|
}
|
|
4519
|
-
this._readyState = WebSocket.CLOSING;
|
|
4520
4547
|
this._sender.close(code, data, !this._isServer, (err) => {
|
|
4521
4548
|
if (err)
|
|
4522
4549
|
return;
|
|
@@ -4525,6 +4552,7 @@ var require_websocket = __commonJS((exports, module) => {
|
|
|
4525
4552
|
this._socket.end();
|
|
4526
4553
|
}
|
|
4527
4554
|
});
|
|
4555
|
+
this._readyState = WebSocket.CLOSING;
|
|
4528
4556
|
setCloseTimer(this);
|
|
4529
4557
|
}
|
|
4530
4558
|
pause() {
|
|
@@ -4712,6 +4740,7 @@ var require_websocket = __commonJS((exports, module) => {
|
|
|
4712
4740
|
socketPath: undefined,
|
|
4713
4741
|
hostname: undefined,
|
|
4714
4742
|
protocol: undefined,
|
|
4743
|
+
protocols: undefined,
|
|
4715
4744
|
timeout: undefined,
|
|
4716
4745
|
method: "GET",
|
|
4717
4746
|
host: undefined,
|
|
@@ -5109,7 +5138,7 @@ var require_websocket = __commonJS((exports, module) => {
|
|
|
5109
5138
|
});
|
|
5110
5139
|
|
|
5111
5140
|
// node_modules/ws/lib/stream.js
|
|
5112
|
-
var require_stream = __commonJS((exports, module)
|
|
5141
|
+
var require_stream = __commonJS(function(exports, module) {
|
|
5113
5142
|
var WebSocket = require_websocket();
|
|
5114
5143
|
var { Duplex } = __require("stream");
|
|
5115
5144
|
function emitClose(stream) {
|
|
@@ -5212,7 +5241,7 @@ var require_stream = __commonJS((exports, module) => {
|
|
|
5212
5241
|
});
|
|
5213
5242
|
|
|
5214
5243
|
// node_modules/ws/lib/subprotocol.js
|
|
5215
|
-
var require_subprotocol = __commonJS((exports, module)
|
|
5244
|
+
var require_subprotocol = __commonJS(function(exports, module) {
|
|
5216
5245
|
var { tokenChars } = require_validation();
|
|
5217
5246
|
function parse(header) {
|
|
5218
5247
|
const protocols = new Set;
|
|
@@ -5257,7 +5286,7 @@ var require_subprotocol = __commonJS((exports, module) => {
|
|
|
5257
5286
|
});
|
|
5258
5287
|
|
|
5259
5288
|
// node_modules/ws/lib/websocket-server.js
|
|
5260
|
-
var require_websocket_server = __commonJS((exports, module)
|
|
5289
|
+
var require_websocket_server = __commonJS(function(exports, module) {
|
|
5261
5290
|
var EventEmitter = __require("events");
|
|
5262
5291
|
var http = __require("http");
|
|
5263
5292
|
var { Duplex } = __require("stream");
|
|
@@ -40807,7 +40836,6 @@ var int64LE = (value) => {
|
|
|
40807
40836
|
};
|
|
40808
40837
|
var readInt32LE = (bytes, offset) => new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getInt32(offset, true);
|
|
40809
40838
|
var readInt64LE = (bytes, offset) => new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getBigInt64(offset, true);
|
|
40810
|
-
var bytesToHex = (bytes) => Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
40811
40839
|
var hexToBytes = (hex) => {
|
|
40812
40840
|
if (hex.length % 2 !== 0 || !/^[0-9a-f]*$/i.test(hex))
|
|
40813
40841
|
throw new RangeError("Invalid hexadecimal bytes");
|
|
@@ -41410,39 +41438,11 @@ var BindingConstructor = {
|
|
|
41410
41438
|
};
|
|
41411
41439
|
var keyIdLong = (key) => new DataView(authKeyId(key).buffer).getBigInt64(0, true);
|
|
41412
41440
|
var encodeBindAuthKeyInner = (value) => concatBytes(uint32LE(BindingConstructor.bindAuthKeyInner), int64LE(value.nonce), int64LE(value.temporaryAuthKeyId), int64LE(value.permanentAuthKeyId), int64LE(value.temporarySessionId), int32LE(value.expiresAt));
|
|
41413
|
-
var decodeBindAuthKeyInner = (body) => {
|
|
41414
|
-
if (body.length !== 40 || readInt32LE(body, 0) >>> 0 !== BindingConstructor.bindAuthKeyInner) {
|
|
41415
|
-
throw new RangeError("Invalid bind_auth_key_inner");
|
|
41416
|
-
}
|
|
41417
|
-
return {
|
|
41418
|
-
nonce: readInt64LE(body, 4),
|
|
41419
|
-
temporaryAuthKeyId: readInt64LE(body, 12),
|
|
41420
|
-
permanentAuthKeyId: readInt64LE(body, 20),
|
|
41421
|
-
temporarySessionId: readInt64LE(body, 28),
|
|
41422
|
-
expiresAt: readInt32LE(body, 36)
|
|
41423
|
-
};
|
|
41424
|
-
};
|
|
41425
41441
|
var encodeBindTempAuthKey = (value) => {
|
|
41426
41442
|
if (value.encryptedMessage.length !== 104)
|
|
41427
41443
|
throw new RangeError("Binding proof must be exactly 104 bytes");
|
|
41428
41444
|
return concatBytes(uint32LE(BindingConstructor.bindTempAuthKey), int64LE(value.permanentAuthKeyId), int64LE(value.nonce), int32LE(value.expiresAt), encodeTlBytes(value.encryptedMessage));
|
|
41429
41445
|
};
|
|
41430
|
-
var decodeBindTempAuthKey = (body) => {
|
|
41431
|
-
if (body.length < 4 || readInt32LE(body, 0) >>> 0 !== BindingConstructor.bindTempAuthKey) {
|
|
41432
|
-
throw new RangeError("Invalid auth.bindTempAuthKey");
|
|
41433
|
-
}
|
|
41434
|
-
const reader = new TlReader(body.slice(4));
|
|
41435
|
-
const value = {
|
|
41436
|
-
permanentAuthKeyId: reader.readLong(),
|
|
41437
|
-
nonce: reader.readLong(),
|
|
41438
|
-
expiresAt: reader.readInt(),
|
|
41439
|
-
encryptedMessage: reader.readBytes()
|
|
41440
|
-
};
|
|
41441
|
-
reader.expectEnd();
|
|
41442
|
-
if (value.encryptedMessage.length !== 104)
|
|
41443
|
-
throw new RangeError("Binding proof must be exactly 104 bytes");
|
|
41444
|
-
return value;
|
|
41445
|
-
};
|
|
41446
41446
|
var deriveV1Aes = (authKey, messageKey) => {
|
|
41447
41447
|
if (authKey.length !== 256 || messageKey.length !== 16)
|
|
41448
41448
|
throw new RangeError("Invalid binding key material");
|
|
@@ -41471,37 +41471,12 @@ var createTemporaryKeyBindingProof = (input) => {
|
|
|
41471
41471
|
const { key, iv } = deriveV1Aes(input.permanentAuthKey, messageKey);
|
|
41472
41472
|
return concatBytes(authKeyId(input.permanentAuthKey), messageKey, aesIgeEncrypt(concatBytes(plaintextWithoutPadding, input.randomPadding), key, iv));
|
|
41473
41473
|
};
|
|
41474
|
-
var verifyTemporaryKeyBindingProof = (input) => {
|
|
41475
|
-
if (input.encryptedMessage.length !== 104 || input.permanentAuthKey.length !== 256) {
|
|
41476
|
-
throw new RangeError("Invalid temporary-key binding proof");
|
|
41477
|
-
}
|
|
41478
|
-
const receivedKeyId = input.encryptedMessage.slice(0, 8);
|
|
41479
|
-
const messageKey = input.encryptedMessage.slice(8, 24);
|
|
41480
|
-
const { key, iv } = deriveV1Aes(input.permanentAuthKey, messageKey);
|
|
41481
|
-
const plaintext = aesIgeDecrypt(input.encryptedMessage.slice(24), key, iv);
|
|
41482
|
-
const plaintextWithoutPadding = plaintext.slice(0, 72);
|
|
41483
|
-
if (!equalBytes(receivedKeyId, authKeyId(input.permanentAuthKey)) || !equalBytes(messageKey, sha1Digest(plaintextWithoutPadding).slice(4, 20))) {
|
|
41484
|
-
throw new RangeError("Invalid temporary-key binding confirmation");
|
|
41485
|
-
}
|
|
41486
|
-
const messageId = readInt64LE(plaintext, 16);
|
|
41487
|
-
const sequenceNumber = readInt32LE(plaintext, 24);
|
|
41488
|
-
const bodyLength = readInt32LE(plaintext, 28);
|
|
41489
|
-
if (sequenceNumber !== 0 || bodyLength !== 40 || plaintext.length !== 80) {
|
|
41490
|
-
throw new RangeError("Invalid isolated binding record");
|
|
41491
|
-
}
|
|
41492
|
-
const inner = decodeBindAuthKeyInner(plaintext.slice(32, 72));
|
|
41493
|
-
if (keyIdLong(input.permanentAuthKey) !== input.outerPermanentAuthKeyId || inner.permanentAuthKeyId !== input.outerPermanentAuthKeyId || inner.temporaryAuthKeyId !== input.outerTemporaryAuthKeyId || inner.temporarySessionId !== input.outerTemporarySessionId || inner.nonce !== input.outerNonce || inner.expiresAt !== input.outerExpiresAt || messageId !== input.outerMessageId || input.outerExpiresAt <= input.nowSeconds || input.outerExpiresAt > input.temporaryKeyExpiresAt + 30)
|
|
41494
|
-
throw new RangeError("Temporary-key binding mismatch");
|
|
41495
|
-
return { inner, messageId };
|
|
41496
|
-
};
|
|
41497
41474
|
// node_modules/@inline-chat/protocol/dist/secure/application.js
|
|
41498
41475
|
var INLINE_RESULT_CONSTRUCTOR = 2889735252;
|
|
41499
41476
|
var INLINE_UPDATE_CONSTRUCTOR = 3695258776;
|
|
41500
41477
|
var INLINE_INVOKE_CONSTRUCTOR = 3950856870;
|
|
41501
41478
|
var INLINE_REALTIME_LAYER = 3;
|
|
41502
41479
|
var encodeInlineInvoke = (payload, layer = INLINE_REALTIME_LAYER) => concatBytes(uint32LE(INLINE_INVOKE_CONSTRUCTOR), int32LE(layer), encodeTlBytes(payload));
|
|
41503
|
-
var encodeInlineResult = (payload) => concatBytes(uint32LE(INLINE_RESULT_CONSTRUCTOR), encodeTlBytes(payload));
|
|
41504
|
-
var encodeInlineUpdate = (payload) => concatBytes(uint32LE(INLINE_UPDATE_CONSTRUCTOR), encodeTlBytes(payload));
|
|
41505
41480
|
var decodeInlineApplicationObject = (bytes) => {
|
|
41506
41481
|
if (bytes.length < 8)
|
|
41507
41482
|
throw new RangeError("Truncated Inline application object");
|
|
@@ -41818,13 +41793,6 @@ var fixed = (name, value, length) => {
|
|
|
41818
41793
|
return value;
|
|
41819
41794
|
};
|
|
41820
41795
|
var encodeReqPqMulti = (nonce) => concatBytes(constructor(HandshakeConstructor.reqPqMulti), fixed("nonce", nonce, 16));
|
|
41821
|
-
var decodeReqPqMulti = (body) => {
|
|
41822
|
-
const reader = constructorReader(body, HandshakeConstructor.reqPqMulti);
|
|
41823
|
-
const nonce = reader.readFixed(16);
|
|
41824
|
-
reader.expectEnd();
|
|
41825
|
-
return { nonce };
|
|
41826
|
-
};
|
|
41827
|
-
var encodeResPq = (nonce, serverNonce, pq, fingerprints) => concatBytes(constructor(HandshakeConstructor.resPq), fixed("nonce", nonce, 16), fixed("server_nonce", serverNonce, 16), encodeTlBytes(pq), encodeTlVector(fingerprints.map(int64LE)));
|
|
41828
41796
|
var decodeResPq = (body) => {
|
|
41829
41797
|
const reader = constructorReader(body, HandshakeConstructor.resPq);
|
|
41830
41798
|
const nonce = reader.readFixed(16);
|
|
@@ -41835,42 +41803,7 @@ var decodeResPq = (body) => {
|
|
|
41835
41803
|
return { nonce, serverNonce, pq, fingerprints };
|
|
41836
41804
|
};
|
|
41837
41805
|
var encodePqInnerData = (value) => concatBytes(constructor(value.temporary ? HandshakeConstructor.pQInnerDataTempDc : HandshakeConstructor.pQInnerDataDc), encodeTlBytes(value.pq), encodeTlBytes(value.p), encodeTlBytes(value.q), fixed("nonce", value.nonce, 16), fixed("server_nonce", value.serverNonce, 16), fixed("new_nonce", value.newNonce, 32), int32LE(value.dc), ...value.temporary ? [int32LE(value.expiresIn ?? 0)] : []);
|
|
41838
|
-
var decodePqInnerDataPrefix = (padded) => {
|
|
41839
|
-
if (padded.length !== 192)
|
|
41840
|
-
throw new RangeError("P_Q inner padded data must be 192 bytes");
|
|
41841
|
-
const id = readInt32LE(padded, 0) >>> 0;
|
|
41842
|
-
const temporary = id === HandshakeConstructor.pQInnerDataTempDc;
|
|
41843
|
-
if (!temporary && id !== HandshakeConstructor.pQInnerDataDc)
|
|
41844
|
-
throw new RangeError("Unexpected P_Q inner constructor");
|
|
41845
|
-
const reader = new TlReader(padded.slice(4));
|
|
41846
|
-
const pq = reader.readBytes();
|
|
41847
|
-
const p = reader.readBytes();
|
|
41848
|
-
const q = reader.readBytes();
|
|
41849
|
-
const nonce = reader.readFixed(16);
|
|
41850
|
-
const serverNonce = reader.readFixed(16);
|
|
41851
|
-
const newNonce = reader.readFixed(32);
|
|
41852
|
-
const dc = reader.readInt();
|
|
41853
|
-
const expiresIn = temporary ? reader.readInt() : undefined;
|
|
41854
|
-
return {
|
|
41855
|
-
value: { temporary, pq, p, q, nonce, serverNonce, newNonce, dc, expiresIn },
|
|
41856
|
-
consumed: 4 + reader.offset
|
|
41857
|
-
};
|
|
41858
|
-
};
|
|
41859
41806
|
var encodeReqDhParams = (value) => concatBytes(constructor(HandshakeConstructor.reqDhParams), fixed("nonce", value.nonce, 16), fixed("server_nonce", value.serverNonce, 16), encodeTlBytes(value.p), encodeTlBytes(value.q), int64LE(value.fingerprint), encodeTlBytes(value.encryptedData));
|
|
41860
|
-
var decodeReqDhParams = (body) => {
|
|
41861
|
-
const reader = constructorReader(body, HandshakeConstructor.reqDhParams);
|
|
41862
|
-
const value = {
|
|
41863
|
-
nonce: reader.readFixed(16),
|
|
41864
|
-
serverNonce: reader.readFixed(16),
|
|
41865
|
-
p: reader.readBytes(),
|
|
41866
|
-
q: reader.readBytes(),
|
|
41867
|
-
fingerprint: reader.readLong(),
|
|
41868
|
-
encryptedData: reader.readBytes()
|
|
41869
|
-
};
|
|
41870
|
-
reader.expectEnd();
|
|
41871
|
-
return value;
|
|
41872
|
-
};
|
|
41873
|
-
var encodeServerDhParamsOk = (nonce, serverNonce, encryptedAnswer) => concatBytes(constructor(HandshakeConstructor.serverDhParamsOk), fixed("nonce", nonce, 16), fixed("server_nonce", serverNonce, 16), encodeTlBytes(encryptedAnswer));
|
|
41874
41807
|
var decodeServerDhParamsOk = (body) => {
|
|
41875
41808
|
const reader = constructorReader(body, HandshakeConstructor.serverDhParamsOk);
|
|
41876
41809
|
const value = { nonce: reader.readFixed(16), serverNonce: reader.readFixed(16), encryptedAnswer: reader.readBytes() };
|
|
@@ -41896,7 +41829,6 @@ var decodeServerDhParams = (body) => {
|
|
|
41896
41829
|
}
|
|
41897
41830
|
throw new RangeError("Unexpected server DH parameters");
|
|
41898
41831
|
};
|
|
41899
|
-
var encodeServerDhInnerData = (value) => concatBytes(constructor(HandshakeConstructor.serverDhInnerData), fixed("nonce", value.nonce, 16), fixed("server_nonce", value.serverNonce, 16), int32LE(value.generator), encodeTlBytes(value.prime), encodeTlBytes(value.gA), int32LE(value.serverTime));
|
|
41900
41832
|
var decodeServerDhInnerDataPrefix = (plaintext) => {
|
|
41901
41833
|
const reader = constructorReaderPrefix(plaintext, HandshakeConstructor.serverDhInnerData);
|
|
41902
41834
|
const value = {
|
|
@@ -41910,24 +41842,7 @@ var decodeServerDhInnerDataPrefix = (plaintext) => {
|
|
|
41910
41842
|
return { value, consumed: 4 + reader.offset };
|
|
41911
41843
|
};
|
|
41912
41844
|
var encodeClientDhInnerData = (value) => concatBytes(constructor(HandshakeConstructor.clientDhInnerData), fixed("nonce", value.nonce, 16), fixed("server_nonce", value.serverNonce, 16), int64LE(value.retryId), encodeTlBytes(value.gB));
|
|
41913
|
-
var decodeClientDhInnerDataPrefix = (plaintext) => {
|
|
41914
|
-
const reader = constructorReaderPrefix(plaintext, HandshakeConstructor.clientDhInnerData);
|
|
41915
|
-
const value = {
|
|
41916
|
-
nonce: reader.readFixed(16),
|
|
41917
|
-
serverNonce: reader.readFixed(16),
|
|
41918
|
-
retryId: reader.readLong(),
|
|
41919
|
-
gB: reader.readBytes()
|
|
41920
|
-
};
|
|
41921
|
-
return { value, consumed: 4 + reader.offset };
|
|
41922
|
-
};
|
|
41923
41845
|
var encodeSetClientDhParams = (nonce, serverNonce, encryptedData) => concatBytes(constructor(HandshakeConstructor.setClientDhParams), fixed("nonce", nonce, 16), fixed("server_nonce", serverNonce, 16), encodeTlBytes(encryptedData));
|
|
41924
|
-
var decodeSetClientDhParams = (body) => {
|
|
41925
|
-
const reader = constructorReader(body, HandshakeConstructor.setClientDhParams);
|
|
41926
|
-
const value = { nonce: reader.readFixed(16), serverNonce: reader.readFixed(16), encryptedData: reader.readBytes() };
|
|
41927
|
-
reader.expectEnd();
|
|
41928
|
-
return value;
|
|
41929
|
-
};
|
|
41930
|
-
var encodeDhGen = (kind, nonce, serverNonce, nonceHash) => concatBytes(constructor(kind === "ok" ? HandshakeConstructor.dhGenOk : kind === "retry" ? HandshakeConstructor.dhGenRetry : HandshakeConstructor.dhGenFail), fixed("nonce", nonce, 16), fixed("server_nonce", serverNonce, 16), fixed("new_nonce_hash", nonceHash, 16));
|
|
41931
41846
|
var decodeDhGen = (body) => {
|
|
41932
41847
|
if (body.length !== 52)
|
|
41933
41848
|
throw new RangeError("Invalid DH generation response");
|
|
@@ -41963,144 +41878,6 @@ var constructorReaderPrefix = (body, expected) => {
|
|
|
41963
41878
|
var PQ = hexToBytes("17ed48941a08f981");
|
|
41964
41879
|
var P = hexToBytes("494c553b");
|
|
41965
41880
|
var Q = hexToBytes("53911073");
|
|
41966
|
-
|
|
41967
|
-
class InlineHandshakeServer {
|
|
41968
|
-
configuration;
|
|
41969
|
-
#phase = { kind: "pq" };
|
|
41970
|
-
constructor(configuration) {
|
|
41971
|
-
this.configuration = configuration;
|
|
41972
|
-
if (configuration.rsaKeys.length < 1)
|
|
41973
|
-
throw new RangeError("At least one server RSA key is required");
|
|
41974
|
-
validateDhParameters(TELEGRAM_DH_PRIME, configuration.generator ?? 3, configuration.randomBytes);
|
|
41975
|
-
}
|
|
41976
|
-
async receive(body) {
|
|
41977
|
-
switch (this.#phase.kind) {
|
|
41978
|
-
case "pq":
|
|
41979
|
-
return this.#receivePq(body);
|
|
41980
|
-
case "dh":
|
|
41981
|
-
return this.#receiveDh(body, this.#phase);
|
|
41982
|
-
case "client-dh":
|
|
41983
|
-
return this.#receiveClientDh(body, this.#phase);
|
|
41984
|
-
case "complete":
|
|
41985
|
-
throw new RangeError("Authorization-key handshake is already complete");
|
|
41986
|
-
}
|
|
41987
|
-
}
|
|
41988
|
-
#receivePq(body) {
|
|
41989
|
-
const { nonce } = decodeReqPqMulti(body);
|
|
41990
|
-
const serverNonce = this.configuration.randomBytes(16);
|
|
41991
|
-
if (serverNonce.length !== 16)
|
|
41992
|
-
throw new RangeError("CSPRNG returned an invalid nonce");
|
|
41993
|
-
this.#phase = { kind: "dh", nonce, serverNonce };
|
|
41994
|
-
return {
|
|
41995
|
-
response: encodeResPq(nonce, serverNonce, PQ, this.configuration.rsaKeys.map((key) => key.fingerprint))
|
|
41996
|
-
};
|
|
41997
|
-
}
|
|
41998
|
-
async#receiveDh(body, phase) {
|
|
41999
|
-
const request = decodeReqDhParams(body);
|
|
42000
|
-
this.#requireNonceChain(request.nonce, request.serverNonce, phase.nonce, phase.serverNonce);
|
|
42001
|
-
if (!equalBytes(request.p, P) || !equalBytes(request.q, Q))
|
|
42002
|
-
throw new RangeError("Invalid pq factorization");
|
|
42003
|
-
const rsaKey = this.configuration.rsaKeys.find((key) => key.fingerprint === request.fingerprint);
|
|
42004
|
-
if (!rsaKey)
|
|
42005
|
-
throw new RangeError("Unknown RSA fingerprint");
|
|
42006
|
-
const decrypted = await rsaKey.rawDecrypt(request.encryptedData);
|
|
42007
|
-
if (decrypted.length !== 256)
|
|
42008
|
-
throw new RangeError("Invalid raw RSA result");
|
|
42009
|
-
const aesEncrypted = decrypted.slice(32);
|
|
42010
|
-
const temporaryKey = xorBytes(decrypted.slice(0, 32), sha256Digest(aesEncrypted));
|
|
42011
|
-
const dataWithHash = aesIgeDecrypt(aesEncrypted, temporaryKey, new Uint8Array(32));
|
|
42012
|
-
const padded = dataWithHash.slice(0, 192).reverse();
|
|
42013
|
-
if (!equalBytes(dataWithHash.slice(192), sha256Digest(temporaryKey, padded))) {
|
|
42014
|
-
throw new RangeError("Invalid RSA_PAD confirmation");
|
|
42015
|
-
}
|
|
42016
|
-
const decoded = decodePqInnerDataPrefix(padded);
|
|
42017
|
-
const inner = decoded.value;
|
|
42018
|
-
this.#requireNonceChain(inner.nonce, inner.serverNonce, phase.nonce, phase.serverNonce);
|
|
42019
|
-
if (!equalBytes(inner.pq, PQ) || !equalBytes(inner.p, P) || !equalBytes(inner.q, Q) || inner.dc !== (this.configuration.dc ?? 1)) {
|
|
42020
|
-
throw new RangeError("Invalid P_Q inner binding");
|
|
42021
|
-
}
|
|
42022
|
-
const now = this.configuration.nowSeconds();
|
|
42023
|
-
let expiresAt;
|
|
42024
|
-
if (inner.temporary) {
|
|
42025
|
-
if (inner.expiresIn !== 86400)
|
|
42026
|
-
throw new RangeError("Temporary authorization key must request 24 hours");
|
|
42027
|
-
expiresAt = now + inner.expiresIn;
|
|
42028
|
-
}
|
|
42029
|
-
const exponent = this.configuration.randomBytes(256);
|
|
42030
|
-
if (exponent.length !== 256)
|
|
42031
|
-
throw new RangeError("CSPRNG returned an invalid DH exponent");
|
|
42032
|
-
const generator = this.configuration.generator ?? 3;
|
|
42033
|
-
const gA = deriveAuthKey(Uint8Array.of(generator), exponent, TELEGRAM_DH_PRIME);
|
|
42034
|
-
validateDhPublicValue(gA, TELEGRAM_DH_PRIME);
|
|
42035
|
-
const serialized = encodeServerDhInnerData({
|
|
42036
|
-
nonce: phase.nonce,
|
|
42037
|
-
serverNonce: phase.serverNonce,
|
|
42038
|
-
generator,
|
|
42039
|
-
prime: TELEGRAM_DH_PRIME,
|
|
42040
|
-
gA,
|
|
42041
|
-
serverTime: now
|
|
42042
|
-
});
|
|
42043
|
-
const paddingLength = (16 - (20 + serialized.length) % 16) % 16;
|
|
42044
|
-
const temporary = deriveTemporaryAes(inner.newNonce, phase.serverNonce);
|
|
42045
|
-
const encryptedAnswer = aesIgeEncrypt(concatBytes(sha1Digest(serialized), serialized, this.configuration.randomBytes(paddingLength)), temporary.key, temporary.iv);
|
|
42046
|
-
this.#phase = {
|
|
42047
|
-
kind: "client-dh",
|
|
42048
|
-
nonce: phase.nonce,
|
|
42049
|
-
serverNonce: phase.serverNonce,
|
|
42050
|
-
newNonce: inner.newNonce,
|
|
42051
|
-
exponent,
|
|
42052
|
-
temporary: inner.temporary,
|
|
42053
|
-
expiresAt,
|
|
42054
|
-
retries: 0,
|
|
42055
|
-
expectedRetryId: 0n
|
|
42056
|
-
};
|
|
42057
|
-
return { response: encodeServerDhParamsOk(phase.nonce, phase.serverNonce, encryptedAnswer) };
|
|
42058
|
-
}
|
|
42059
|
-
async#receiveClientDh(body, phase) {
|
|
42060
|
-
const request = decodeSetClientDhParams(body);
|
|
42061
|
-
this.#requireNonceChain(request.nonce, request.serverNonce, phase.nonce, phase.serverNonce);
|
|
42062
|
-
const temporary = deriveTemporaryAes(phase.newNonce, phase.serverNonce);
|
|
42063
|
-
const plaintext = aesIgeDecrypt(request.encryptedData, temporary.key, temporary.iv);
|
|
42064
|
-
const decoded = decodeClientDhInnerDataPrefix(plaintext.slice(20));
|
|
42065
|
-
const paddingLength = plaintext.length - 20 - decoded.consumed;
|
|
42066
|
-
if (paddingLength < 0 || paddingLength > 15 || !equalBytes(plaintext.slice(0, 20), sha1Digest(plaintext.slice(20, 20 + decoded.consumed)))) {
|
|
42067
|
-
throw new RangeError("Invalid client DH inner confirmation");
|
|
42068
|
-
}
|
|
42069
|
-
this.#requireNonceChain(decoded.value.nonce, decoded.value.serverNonce, phase.nonce, phase.serverNonce);
|
|
42070
|
-
if (decoded.value.retryId !== phase.expectedRetryId) {
|
|
42071
|
-
throw new RangeError("Invalid DH retry identifier");
|
|
42072
|
-
}
|
|
42073
|
-
validateDhPublicValue(decoded.value.gB, TELEGRAM_DH_PRIME);
|
|
42074
|
-
const authKey = deriveAuthKey(decoded.value.gB, phase.exponent, TELEGRAM_DH_PRIME);
|
|
42075
|
-
const established = {
|
|
42076
|
-
key: authKey,
|
|
42077
|
-
keyId: authKeyId(authKey),
|
|
42078
|
-
temporary: phase.temporary,
|
|
42079
|
-
expiresAt: phase.expiresAt,
|
|
42080
|
-
serverSalt: initialServerSalt(phase.newNonce, phase.serverNonce)
|
|
42081
|
-
};
|
|
42082
|
-
const created = await this.configuration.authorizationKeys.create(established);
|
|
42083
|
-
if (created === "collision") {
|
|
42084
|
-
if (phase.retries >= 4) {
|
|
42085
|
-
this.#phase = { kind: "complete" };
|
|
42086
|
-
return { response: encodeDhGen("fail", phase.nonce, phase.serverNonce, newNonceHash(phase.newNonce, 3, authKey)) };
|
|
42087
|
-
}
|
|
42088
|
-
this.#phase = { ...phase, retries: phase.retries + 1, expectedRetryId: bindRetryId(authKey) };
|
|
42089
|
-
return { response: encodeDhGen("retry", phase.nonce, phase.serverNonce, newNonceHash(phase.newNonce, 2, authKey)) };
|
|
42090
|
-
}
|
|
42091
|
-
this.#phase = { kind: "complete" };
|
|
42092
|
-
return {
|
|
42093
|
-
response: encodeDhGen("ok", phase.nonce, phase.serverNonce, newNonceHash(phase.newNonce, 1, authKey)),
|
|
42094
|
-
established
|
|
42095
|
-
};
|
|
42096
|
-
}
|
|
42097
|
-
#requireNonceChain(actualNonce, actualServer, nonce, serverNonce) {
|
|
42098
|
-
if (!equalBytes(actualNonce, nonce) || !equalBytes(actualServer, serverNonce)) {
|
|
42099
|
-
throw new RangeError("Handshake nonce chain mismatch");
|
|
42100
|
-
}
|
|
42101
|
-
}
|
|
42102
|
-
}
|
|
42103
|
-
|
|
42104
41881
|
class InlineHandshakeClient {
|
|
42105
41882
|
configuration;
|
|
42106
41883
|
#phase = { kind: "idle" };
|
|
@@ -42342,54 +42119,6 @@ var decryptRecordWithMetadata = (record, authKey, validation) => {
|
|
|
42342
42119
|
};
|
|
42343
42120
|
var decryptRecord = (record, authKey, validation) => decryptRecordWithMetadata(record, authKey, validation).fields;
|
|
42344
42121
|
// node_modules/@inline-chat/protocol/dist/secure/session.js
|
|
42345
|
-
class ReceiveMessageWindow {
|
|
42346
|
-
#capacity;
|
|
42347
|
-
#accepted = new Set;
|
|
42348
|
-
#highest;
|
|
42349
|
-
constructor(capacity = 1000) {
|
|
42350
|
-
if (!Number.isSafeInteger(capacity) || capacity < 1)
|
|
42351
|
-
throw new RangeError("Receive window capacity must be positive");
|
|
42352
|
-
this.#capacity = capacity;
|
|
42353
|
-
}
|
|
42354
|
-
claim(messageId) {
|
|
42355
|
-
if (this.#accepted.has(messageId))
|
|
42356
|
-
return false;
|
|
42357
|
-
if (this.#highest !== undefined && messageId < this.#highest && this.#accepted.size >= this.#capacity) {
|
|
42358
|
-
const minimum = this.minimum;
|
|
42359
|
-
if (minimum !== undefined && messageId < minimum)
|
|
42360
|
-
return false;
|
|
42361
|
-
}
|
|
42362
|
-
this.#accepted.add(messageId);
|
|
42363
|
-
if (this.#highest === undefined || messageId > this.#highest)
|
|
42364
|
-
this.#highest = messageId;
|
|
42365
|
-
if (this.#accepted.size > this.#capacity) {
|
|
42366
|
-
const ordered = [...this.#accepted].sort((left, right) => left < right ? -1 : left > right ? 1 : 0);
|
|
42367
|
-
for (let index = 0;index < ordered.length - this.#capacity; index += 1)
|
|
42368
|
-
this.#accepted.delete(ordered[index]);
|
|
42369
|
-
}
|
|
42370
|
-
return true;
|
|
42371
|
-
}
|
|
42372
|
-
has(messageId) {
|
|
42373
|
-
return this.#accepted.has(messageId);
|
|
42374
|
-
}
|
|
42375
|
-
get minimum() {
|
|
42376
|
-
let minimum;
|
|
42377
|
-
for (const value of this.#accepted)
|
|
42378
|
-
if (minimum === undefined || value < minimum)
|
|
42379
|
-
minimum = value;
|
|
42380
|
-
return minimum;
|
|
42381
|
-
}
|
|
42382
|
-
checkpoint() {
|
|
42383
|
-
return { accepted: [...this.#accepted], highest: this.#highest };
|
|
42384
|
-
}
|
|
42385
|
-
restore(checkpoint) {
|
|
42386
|
-
this.#accepted.clear();
|
|
42387
|
-
for (const messageId of checkpoint.accepted)
|
|
42388
|
-
this.#accepted.add(messageId);
|
|
42389
|
-
this.#highest = checkpoint.highest;
|
|
42390
|
-
}
|
|
42391
|
-
}
|
|
42392
|
-
|
|
42393
42122
|
class MessageIdGenerator {
|
|
42394
42123
|
#last = 0n;
|
|
42395
42124
|
next(estimatedServerUnixMillis, randomLowBits, modulo) {
|
|
@@ -42449,158 +42178,8 @@ class AuthenticatedServerClock {
|
|
|
42449
42178
|
return this.#serverUnixMilliseconds + elapsed;
|
|
42450
42179
|
}
|
|
42451
42180
|
}
|
|
42452
|
-
var validateInboundMessageId = (messageId, direction, nowSeconds) => {
|
|
42453
|
-
if (messageId === 0n || !Number.isFinite(nowSeconds))
|
|
42454
|
-
return { kind: "bad", errorCode: 18 };
|
|
42455
|
-
const validDirection = direction === "client" ? (messageId & 3n) === 0n && (messageId & 0xffffffffn) !== 0n : (messageId & 1n) === 1n;
|
|
42456
|
-
if (!validDirection)
|
|
42457
|
-
return { kind: "bad", errorCode: 18 };
|
|
42458
|
-
const seconds = Number(messageId >> 32n);
|
|
42459
|
-
if (seconds > nowSeconds + 30)
|
|
42460
|
-
return { kind: "bad", errorCode: 17 };
|
|
42461
|
-
if (seconds < nowSeconds - 300)
|
|
42462
|
-
return { kind: "bad", errorCode: 20 };
|
|
42463
|
-
return { kind: "valid" };
|
|
42464
|
-
};
|
|
42465
|
-
|
|
42466
|
-
class ReceiveSequenceValidator {
|
|
42467
|
-
#received = [];
|
|
42468
|
-
validate(messageId, sequenceNumber, contentRelated) {
|
|
42469
|
-
if (!Number.isSafeInteger(sequenceNumber) || sequenceNumber < 0)
|
|
42470
|
-
return 32;
|
|
42471
|
-
if (contentRelated && sequenceNumber % 2 === 0)
|
|
42472
|
-
return 35;
|
|
42473
|
-
if (!contentRelated && sequenceNumber % 2 !== 0)
|
|
42474
|
-
return 34;
|
|
42475
|
-
let insertion = this.#received.findIndex((value) => value.messageId > messageId);
|
|
42476
|
-
if (insertion < 0)
|
|
42477
|
-
insertion = this.#received.length;
|
|
42478
|
-
const previous = this.#received[insertion - 1];
|
|
42479
|
-
const next = this.#received[insertion];
|
|
42480
|
-
if (previous && previous.sequenceNumber > sequenceNumber)
|
|
42481
|
-
return 32;
|
|
42482
|
-
if (next && next.sequenceNumber < sequenceNumber)
|
|
42483
|
-
return 33;
|
|
42484
|
-
this.#received.splice(insertion, 0, { messageId, sequenceNumber });
|
|
42485
|
-
if (this.#received.length > 1000)
|
|
42486
|
-
this.#received.splice(0, this.#received.length - 1000);
|
|
42487
|
-
return;
|
|
42488
|
-
}
|
|
42489
|
-
checkpoint() {
|
|
42490
|
-
return this.#received.map((value) => ({ ...value }));
|
|
42491
|
-
}
|
|
42492
|
-
restore(checkpoint) {
|
|
42493
|
-
this.#received.splice(0, this.#received.length, ...checkpoint.map((value) => ({ ...value })));
|
|
42494
|
-
}
|
|
42495
|
-
}
|
|
42496
|
-
|
|
42497
|
-
class AcknowledgementQueue {
|
|
42498
|
-
#pending = new Set;
|
|
42499
|
-
add(messageId) {
|
|
42500
|
-
if (this.#pending.size >= 8192 && !this.#pending.has(messageId))
|
|
42501
|
-
throw new RangeError("Acknowledgement queue is full");
|
|
42502
|
-
this.#pending.add(messageId);
|
|
42503
|
-
}
|
|
42504
|
-
drain(maximum = 8192) {
|
|
42505
|
-
if (!Number.isSafeInteger(maximum) || maximum < 1 || maximum > 8192)
|
|
42506
|
-
throw new RangeError("Invalid ACK batch size");
|
|
42507
|
-
const result = [];
|
|
42508
|
-
for (const messageId of this.#pending) {
|
|
42509
|
-
result.push(messageId);
|
|
42510
|
-
this.#pending.delete(messageId);
|
|
42511
|
-
if (result.length === maximum)
|
|
42512
|
-
break;
|
|
42513
|
-
}
|
|
42514
|
-
return result;
|
|
42515
|
-
}
|
|
42516
|
-
}
|
|
42517
|
-
|
|
42518
|
-
class PendingMessageCache {
|
|
42519
|
-
capacity;
|
|
42520
|
-
byteCapacity;
|
|
42521
|
-
#messages = new Map;
|
|
42522
|
-
#retainedBytes = 0;
|
|
42523
|
-
constructor(capacity = 8192, byteCapacity = 32 * 1024 * 1024) {
|
|
42524
|
-
this.capacity = capacity;
|
|
42525
|
-
this.byteCapacity = byteCapacity;
|
|
42526
|
-
if (!Number.isSafeInteger(capacity) || capacity < 1 || capacity > 8192)
|
|
42527
|
-
throw new RangeError("Invalid pending-message capacity");
|
|
42528
|
-
if (!Number.isSafeInteger(byteCapacity) || byteCapacity < 1)
|
|
42529
|
-
throw new RangeError("Invalid pending-message byte capacity");
|
|
42530
|
-
}
|
|
42531
|
-
get retainedBytes() {
|
|
42532
|
-
return this.#retainedBytes;
|
|
42533
|
-
}
|
|
42534
|
-
retain(message) {
|
|
42535
|
-
if (this.#messages.size >= this.capacity && !this.#messages.has(message.messageId)) {
|
|
42536
|
-
throw new RangeError("Pending-message cache is full");
|
|
42537
|
-
}
|
|
42538
|
-
const previous = this.#messages.get(message.messageId);
|
|
42539
|
-
const nextBytes = this.#retainedBytes - (previous?.body.length ?? 0) + message.body.length;
|
|
42540
|
-
if (nextBytes > this.byteCapacity)
|
|
42541
|
-
throw new RangeError("Pending-message byte capacity exceeded");
|
|
42542
|
-
const body = message.body.slice();
|
|
42543
|
-
this.#messages.set(message.messageId, { ...message, body });
|
|
42544
|
-
this.#retainedBytes = nextBytes;
|
|
42545
|
-
}
|
|
42546
|
-
acknowledge(messageIds) {
|
|
42547
|
-
for (const messageId of messageIds) {
|
|
42548
|
-
const message = this.#messages.get(messageId);
|
|
42549
|
-
if (!message)
|
|
42550
|
-
continue;
|
|
42551
|
-
this.#messages.delete(messageId);
|
|
42552
|
-
this.#retainedBytes -= message.body.length;
|
|
42553
|
-
}
|
|
42554
|
-
}
|
|
42555
|
-
resend(messageIds) {
|
|
42556
|
-
return messageIds.flatMap((messageId) => {
|
|
42557
|
-
const message = this.#messages.get(messageId);
|
|
42558
|
-
return message ? [{ ...message, body: message.body.slice() }] : [];
|
|
42559
|
-
});
|
|
42560
|
-
}
|
|
42561
|
-
state(messageIds) {
|
|
42562
|
-
return Uint8Array.from(messageIds, (messageId) => this.#messages.has(messageId) ? 4 : 1);
|
|
42563
|
-
}
|
|
42564
|
-
dropRpcResult(requestMessageId) {
|
|
42565
|
-
for (const [messageId, message] of this.#messages) {
|
|
42566
|
-
if (message.body.length < 12)
|
|
42567
|
-
continue;
|
|
42568
|
-
const view = new DataView(message.body.buffer, message.body.byteOffset, message.body.byteLength);
|
|
42569
|
-
if (view.getUint32(0, true) !== 4082920705 || view.getBigInt64(4, true) !== requestMessageId)
|
|
42570
|
-
continue;
|
|
42571
|
-
this.#messages.delete(messageId);
|
|
42572
|
-
this.#retainedBytes -= message.body.length;
|
|
42573
|
-
return { ...message, body: message.body.slice() };
|
|
42574
|
-
}
|
|
42575
|
-
return;
|
|
42576
|
-
}
|
|
42577
|
-
}
|
|
42578
|
-
|
|
42579
|
-
class BadMessageRecovery {
|
|
42580
|
-
#outstanding = new Map;
|
|
42581
|
-
add(messageId, sequenceNumber) {
|
|
42582
|
-
if (this.#outstanding.size >= 8192 && !this.#outstanding.has(messageId))
|
|
42583
|
-
throw new RangeError("Outstanding-message limit reached");
|
|
42584
|
-
this.#outstanding.set(messageId, sequenceNumber);
|
|
42585
|
-
}
|
|
42586
|
-
accept(input) {
|
|
42587
|
-
const sequence = this.#outstanding.get(input.badMessageId);
|
|
42588
|
-
if (sequence === undefined || sequence !== input.badSequenceNumber)
|
|
42589
|
-
return { kind: "fatal" };
|
|
42590
|
-
if (input.errorCode === 16 || input.errorCode === 17) {
|
|
42591
|
-
if ((input.outerServerMessageId & 1n) !== 1n)
|
|
42592
|
-
return { kind: "fatal" };
|
|
42593
|
-
return { kind: "time", serverSeconds: Number(input.outerServerMessageId >> 32n) };
|
|
42594
|
-
}
|
|
42595
|
-
if (input.errorCode === 48)
|
|
42596
|
-
return { kind: "salt" };
|
|
42597
|
-
return { kind: "fatal" };
|
|
42598
|
-
}
|
|
42599
|
-
}
|
|
42600
42181
|
// node_modules/@inline-chat/protocol/dist/secure/service.js
|
|
42601
|
-
var MAX_CONTAINER_MESSAGES = 1024;
|
|
42602
42182
|
var MAX_SERVICE_MESSAGE_IDS = 8192;
|
|
42603
|
-
var MAX_GZIP_OUTPUT_BYTES = MAX_PACKET_BYTES;
|
|
42604
42183
|
var ServiceConstructor = {
|
|
42605
42184
|
rpcResult: 4082920705,
|
|
42606
42185
|
rpcError: 558156313,
|
|
@@ -42656,61 +42235,6 @@ var decodeMessageIds = (body, expected) => {
|
|
|
42656
42235
|
reader.expectEnd();
|
|
42657
42236
|
return ids;
|
|
42658
42237
|
};
|
|
42659
|
-
var decodeMessageContainer = (body) => {
|
|
42660
|
-
const reader = readerFor(body, ServiceConstructor.msgContainer);
|
|
42661
|
-
const count = reader.readInt();
|
|
42662
|
-
if (count < 1 || count > MAX_CONTAINER_MESSAGES)
|
|
42663
|
-
throw new RangeError("Invalid message-container count");
|
|
42664
|
-
const messages = [];
|
|
42665
|
-
for (let index = 0;index < count; index += 1) {
|
|
42666
|
-
const messageId = reader.readLong();
|
|
42667
|
-
const sequenceNumber = reader.readInt();
|
|
42668
|
-
const bytes = reader.readInt();
|
|
42669
|
-
if (bytes < 4 || bytes > MAX_PACKET_BYTES || bytes % 4 !== 0)
|
|
42670
|
-
throw new RangeError("Invalid contained body length");
|
|
42671
|
-
const child = reader.readFixed(bytes);
|
|
42672
|
-
if (readInt32LE(child, 0) >>> 0 === ServiceConstructor.msgContainer) {
|
|
42673
|
-
throw new RangeError("Nested message containers are forbidden");
|
|
42674
|
-
}
|
|
42675
|
-
messages.push({ messageId, sequenceNumber, body: child });
|
|
42676
|
-
}
|
|
42677
|
-
reader.expectEnd();
|
|
42678
|
-
return messages;
|
|
42679
|
-
};
|
|
42680
|
-
var decodeMsgCopy = (body) => {
|
|
42681
|
-
const reader = readerFor(body, ServiceConstructor.msgCopy);
|
|
42682
|
-
const messageId = reader.readLong();
|
|
42683
|
-
const sequenceNumber = reader.readInt();
|
|
42684
|
-
const length = reader.readInt();
|
|
42685
|
-
if (length < 4 || length > MAX_PACKET_BYTES || length % 4 !== 0) {
|
|
42686
|
-
throw new RangeError("Invalid copied body length");
|
|
42687
|
-
}
|
|
42688
|
-
const copied = reader.readFixed(length);
|
|
42689
|
-
reader.expectEnd();
|
|
42690
|
-
if (readInt32LE(copied, 0) >>> 0 === ServiceConstructor.msgContainer) {
|
|
42691
|
-
throw new RangeError("A copied message cannot contain a container");
|
|
42692
|
-
}
|
|
42693
|
-
return { messageId, sequenceNumber, body: copied };
|
|
42694
|
-
};
|
|
42695
|
-
var decodeInvokeAfter = (body) => {
|
|
42696
|
-
const id = serviceConstructor(body);
|
|
42697
|
-
const reader = readerFor(body, id);
|
|
42698
|
-
let messageIds;
|
|
42699
|
-
if (id === ServiceConstructor.invokeAfterMsg) {
|
|
42700
|
-
messageIds = [reader.readLong()];
|
|
42701
|
-
} else if (id === ServiceConstructor.invokeAfterMsgs) {
|
|
42702
|
-
messageIds = reader.readVector((item) => item.readLong(), MAX_SERVICE_MESSAGE_IDS);
|
|
42703
|
-
} else {
|
|
42704
|
-
throw new RangeError("Unexpected invoke-after constructor");
|
|
42705
|
-
}
|
|
42706
|
-
const query = reader.readFixed(reader.remaining);
|
|
42707
|
-
requireAlignedBody(query);
|
|
42708
|
-
return { messageIds, query };
|
|
42709
|
-
};
|
|
42710
|
-
var encodeRpcResult = (requestMessageId, result) => {
|
|
42711
|
-
requireAlignedBody(result);
|
|
42712
|
-
return fixedBody(ServiceConstructor.rpcResult, int64LE(requestMessageId), result);
|
|
42713
|
-
};
|
|
42714
42238
|
var decodeRpcResult = (body) => {
|
|
42715
42239
|
const reader = readerFor(body, ServiceConstructor.rpcResult);
|
|
42716
42240
|
const requestMessageId = reader.readLong();
|
|
@@ -42718,7 +42242,6 @@ var decodeRpcResult = (body) => {
|
|
|
42718
42242
|
requireAlignedBody(result);
|
|
42719
42243
|
return { requestMessageId, result };
|
|
42720
42244
|
};
|
|
42721
|
-
var encodeRpcError = (code, message) => fixedBody(ServiceConstructor.rpcError, int32LE(code), encodeTlBytes(new TextEncoder().encode(message)));
|
|
42722
42245
|
var decodeRpcError = (body) => {
|
|
42723
42246
|
const reader = readerFor(body, ServiceConstructor.rpcError);
|
|
42724
42247
|
const code = reader.readInt();
|
|
@@ -42726,54 +42249,8 @@ var decodeRpcError = (body) => {
|
|
|
42726
42249
|
reader.expectEnd();
|
|
42727
42250
|
return { code, message };
|
|
42728
42251
|
};
|
|
42729
|
-
var decodeRpcDropAnswer = (body) => {
|
|
42730
|
-
const reader = readerFor(body, ServiceConstructor.rpcDropAnswer);
|
|
42731
|
-
const requestMessageId = reader.readLong();
|
|
42732
|
-
reader.expectEnd();
|
|
42733
|
-
return requestMessageId;
|
|
42734
|
-
};
|
|
42735
|
-
var encodeRpcDropAnswerResult = (result) => {
|
|
42736
|
-
if (result.kind === "unknown")
|
|
42737
|
-
return fixedBody(ServiceConstructor.rpcAnswerUnknown);
|
|
42738
|
-
if (result.kind === "running")
|
|
42739
|
-
return fixedBody(ServiceConstructor.rpcAnswerDroppedRunning);
|
|
42740
|
-
if (!Number.isSafeInteger(result.bytes) || result.bytes < 0 || result.bytes > MAX_PACKET_BYTES) {
|
|
42741
|
-
throw new RangeError("Invalid dropped-answer byte count");
|
|
42742
|
-
}
|
|
42743
|
-
return fixedBody(ServiceConstructor.rpcAnswerDropped, int64LE(result.messageId), int32LE(result.sequenceNumber), int32LE(result.bytes));
|
|
42744
|
-
};
|
|
42745
|
-
var decodeHttpWait = (body) => {
|
|
42746
|
-
const reader = readerFor(body, ServiceConstructor.httpWait);
|
|
42747
|
-
const result = {
|
|
42748
|
-
maximumDelay: reader.readInt(),
|
|
42749
|
-
waitAfter: reader.readInt(),
|
|
42750
|
-
maximumWait: reader.readInt()
|
|
42751
|
-
};
|
|
42752
|
-
reader.expectEnd();
|
|
42753
|
-
if (Object.values(result).some((value) => value < 0))
|
|
42754
|
-
throw new RangeError("Invalid HTTP wait interval");
|
|
42755
|
-
return result;
|
|
42756
|
-
};
|
|
42757
42252
|
var encodeMsgsAck = (messageIds) => encodeMessageIds(ServiceConstructor.msgsAck, messageIds);
|
|
42758
42253
|
var decodeMsgsAck = (body) => decodeMessageIds(body, ServiceConstructor.msgsAck);
|
|
42759
|
-
var decodeMsgResendReq = (body) => decodeMessageIds(body, ServiceConstructor.msgResendReq);
|
|
42760
|
-
var decodeMsgsStateReq = (body) => decodeMessageIds(body, ServiceConstructor.msgsStateReq);
|
|
42761
|
-
var encodeMsgsStateInfo = (requestMessageId, states) => {
|
|
42762
|
-
if (states.length > MAX_SERVICE_MESSAGE_IDS)
|
|
42763
|
-
throw new RangeError("Too many message states");
|
|
42764
|
-
return fixedBody(ServiceConstructor.msgsStateInfo, int64LE(requestMessageId), encodeTlBytes(states));
|
|
42765
|
-
};
|
|
42766
|
-
var decodeMsgsAllInfo = (body) => {
|
|
42767
|
-
const reader = readerFor(body, ServiceConstructor.msgsAllInfo);
|
|
42768
|
-
const messageIds = reader.readVector((item) => item.readLong(), MAX_SERVICE_MESSAGE_IDS);
|
|
42769
|
-
const states = reader.readBytes();
|
|
42770
|
-
reader.expectEnd();
|
|
42771
|
-
if (messageIds.length !== states.length)
|
|
42772
|
-
throw new RangeError("Message-state cardinality mismatch");
|
|
42773
|
-
return { messageIds, states };
|
|
42774
|
-
};
|
|
42775
|
-
var encodeBadMsgNotification = (badMessageId, badSequenceNumber, errorCode) => fixedBody(ServiceConstructor.badMsgNotification, int64LE(badMessageId), int32LE(badSequenceNumber), int32LE(errorCode));
|
|
42776
|
-
var encodeBadServerSalt = (badMessageId, badSequenceNumber, errorCode, newServerSalt) => fixedBody(ServiceConstructor.badServerSalt, int64LE(badMessageId), int32LE(badSequenceNumber), int32LE(errorCode), int64LE(newServerSalt));
|
|
42777
42254
|
var decodeBadMessageNotification = (body) => {
|
|
42778
42255
|
if (body.length !== 20 && body.length !== 28)
|
|
42779
42256
|
throw new RangeError("Invalid bad-message notification");
|
|
@@ -42792,46 +42269,6 @@ var decodeBadMessageNotification = (body) => {
|
|
|
42792
42269
|
};
|
|
42793
42270
|
};
|
|
42794
42271
|
var encodePing = (pingId) => fixedBody(ServiceConstructor.ping, int64LE(pingId));
|
|
42795
|
-
var encodePong = (messageId, pingId) => fixedBody(ServiceConstructor.pong, int64LE(messageId), int64LE(pingId));
|
|
42796
|
-
var encodeNewSessionCreated = (firstMessageId, uniqueId, serverSalt) => fixedBody(ServiceConstructor.newSessionCreated, int64LE(firstMessageId), int64LE(uniqueId), int64LE(serverSalt));
|
|
42797
|
-
var decodeGetFutureSalts = (body) => {
|
|
42798
|
-
const reader = readerFor(body, ServiceConstructor.getFutureSalts);
|
|
42799
|
-
const count = reader.readInt();
|
|
42800
|
-
reader.expectEnd();
|
|
42801
|
-
if (count < 1 || count > 64)
|
|
42802
|
-
throw new RangeError("Invalid future-salt count");
|
|
42803
|
-
return count;
|
|
42804
|
-
};
|
|
42805
|
-
var encodeFutureSalts = (requestMessageId, now, salts) => {
|
|
42806
|
-
if (salts.length < 1 || salts.length > 64)
|
|
42807
|
-
throw new RangeError("Invalid future-salt count");
|
|
42808
|
-
return fixedBody(ServiceConstructor.futureSalts, int64LE(requestMessageId), int32LE(now), encodeTlVector(salts.map((salt) => {
|
|
42809
|
-
if (!Number.isInteger(salt.validSince) || !Number.isInteger(salt.validUntil) || salt.validUntil <= salt.validSince)
|
|
42810
|
-
throw new RangeError("Invalid future-salt interval");
|
|
42811
|
-
return fixedBody(ServiceConstructor.futureSalt, int32LE(salt.validSince), int32LE(salt.validUntil), int64LE(salt.salt));
|
|
42812
|
-
})));
|
|
42813
|
-
};
|
|
42814
|
-
var decodeDestroySession = (body) => {
|
|
42815
|
-
const reader = readerFor(body, ServiceConstructor.destroySession);
|
|
42816
|
-
const sessionId = reader.readLong();
|
|
42817
|
-
reader.expectEnd();
|
|
42818
|
-
return sessionId;
|
|
42819
|
-
};
|
|
42820
|
-
var encodeDestroySessionResult = (sessionId, found) => fixedBody(found ? ServiceConstructor.destroySessionOk : ServiceConstructor.destroySessionNone, int64LE(sessionId));
|
|
42821
|
-
var encodeDestroyAuthKeyResult = (result) => fixedBody(result === "ok" ? ServiceConstructor.destroyAuthKeyOk : result === "none" ? ServiceConstructor.destroyAuthKeyNone : ServiceConstructor.destroyAuthKeyFail);
|
|
42822
|
-
var decodeGzipPacked = (body, gunzip, maximumOutputBytes = MAX_GZIP_OUTPUT_BYTES) => {
|
|
42823
|
-
if (maximumOutputBytes < 4 || maximumOutputBytes > MAX_GZIP_OUTPUT_BYTES) {
|
|
42824
|
-
throw new RangeError("Invalid gzip output limit");
|
|
42825
|
-
}
|
|
42826
|
-
const reader = readerFor(body, ServiceConstructor.gzipPacked);
|
|
42827
|
-
const packed = reader.readBytes();
|
|
42828
|
-
reader.expectEnd();
|
|
42829
|
-
const unpacked = gunzip(packed, maximumOutputBytes);
|
|
42830
|
-
if (unpacked.length < 4 || unpacked.length > maximumOutputBytes || unpacked.length % 4 !== 0) {
|
|
42831
|
-
throw new RangeError("Invalid decompressed MTProto object");
|
|
42832
|
-
}
|
|
42833
|
-
return unpacked;
|
|
42834
|
-
};
|
|
42835
42272
|
var serviceConstructor = (body) => {
|
|
42836
42273
|
requireAlignedBody(body);
|
|
42837
42274
|
return readInt32LE(body, 0) >>> 0;
|
|
@@ -42843,27 +42280,6 @@ var readerFor = (body, expected) => {
|
|
|
42843
42280
|
return new TlReader(body.slice(4));
|
|
42844
42281
|
};
|
|
42845
42282
|
// node_modules/@inline-chat/protocol/dist/secure/serverSession.js
|
|
42846
|
-
var BOOL_TRUE = 2574415285;
|
|
42847
|
-
var MAX_SESSION_OUTPUTS = 2048;
|
|
42848
|
-
var MAX_COMPLETED_INCOMING_MESSAGES = 8192;
|
|
42849
|
-
var MAX_DEFERRED_INVOKE_AFTER = 1024;
|
|
42850
|
-
var MAX_IN_FLIGHT_APPLICATIONS = 64;
|
|
42851
|
-
var MAX_INVOKE_AFTER_NESTING = 16;
|
|
42852
|
-
var DEFAULT_APPLICATION_TIMEOUT_MS = 30000;
|
|
42853
|
-
|
|
42854
|
-
class InlineProtocolAuthorizationInvalidated extends Error {
|
|
42855
|
-
constructor() {
|
|
42856
|
-
super("Authorization key is no longer active");
|
|
42857
|
-
this.name = "InlineProtocolAuthorizationInvalidated";
|
|
42858
|
-
}
|
|
42859
|
-
}
|
|
42860
|
-
|
|
42861
|
-
class InlineProtocolApplicationOutputOverloaded extends Error {
|
|
42862
|
-
constructor() {
|
|
42863
|
-
super("Inline Protocol application update capacity exceeded");
|
|
42864
|
-
this.name = "InlineProtocolApplicationOutputOverloaded";
|
|
42865
|
-
}
|
|
42866
|
-
}
|
|
42867
42283
|
var NON_CONTENT_CONSTRUCTORS = new Set([
|
|
42868
42284
|
ServiceConstructor.msgContainer,
|
|
42869
42285
|
ServiceConstructor.msgsAck,
|
|
@@ -42878,861 +42294,8 @@ var NON_CONTENT_CONSTRUCTORS = new Set([
|
|
|
42878
42294
|
ServiceConstructor.pong,
|
|
42879
42295
|
ServiceConstructor.httpWait
|
|
42880
42296
|
]);
|
|
42881
|
-
|
|
42882
|
-
class InlineProtocolServerSession {
|
|
42883
|
-
options;
|
|
42884
|
-
#messageIds = new MessageIdGenerator;
|
|
42885
|
-
#sequenceNumbers = new SequenceNumberGenerator;
|
|
42886
|
-
#receivedIds = new ReceiveMessageWindow;
|
|
42887
|
-
#receivedSequences = new ReceiveSequenceValidator;
|
|
42888
|
-
#acknowledgements = new AcknowledgementQueue;
|
|
42889
|
-
#pending = new PendingMessageCache;
|
|
42890
|
-
#completedIncoming = new Map;
|
|
42891
|
-
#deferredInvokeAfter = new Map;
|
|
42892
|
-
#inFlightApplications = new Set;
|
|
42893
|
-
#droppedApplicationAnswers = new Set;
|
|
42894
|
-
#handshake;
|
|
42895
|
-
#authorization;
|
|
42896
|
-
#sessionId;
|
|
42897
|
-
#destroyed = false;
|
|
42898
|
-
constructor(options) {
|
|
42899
|
-
this.options = options;
|
|
42900
|
-
const applicationTimeoutMs = options.applicationTimeoutMs ?? DEFAULT_APPLICATION_TIMEOUT_MS;
|
|
42901
|
-
if (!Number.isSafeInteger(applicationTimeoutMs) || applicationTimeoutMs < 1) {
|
|
42902
|
-
throw new RangeError("Invalid Inline Protocol application timeout");
|
|
42903
|
-
}
|
|
42904
|
-
this.#handshake = new InlineHandshakeServer({
|
|
42905
|
-
rsaKeys: options.rsaKeys,
|
|
42906
|
-
randomBytes: options.randomBytes,
|
|
42907
|
-
nowSeconds: () => Math.floor(options.nowMilliseconds() / 1000),
|
|
42908
|
-
authorizationKeys: {
|
|
42909
|
-
create: (key) => options.authorizationKeys.create(key)
|
|
42910
|
-
},
|
|
42911
|
-
dc: options.dc
|
|
42912
|
-
});
|
|
42913
|
-
}
|
|
42914
|
-
get destroyed() {
|
|
42915
|
-
return this.#destroyed;
|
|
42916
|
-
}
|
|
42917
|
-
get hasEstablishedAuthorization() {
|
|
42918
|
-
return this.#authorization !== undefined;
|
|
42919
|
-
}
|
|
42920
|
-
async receive(payload, receiveOptions = {}) {
|
|
42921
|
-
const accepted = await this.receiveConcurrent(payload, receiveOptions);
|
|
42922
|
-
const responses = [...accepted.responses];
|
|
42923
|
-
const applicationTasks = [...accepted.applicationTasks];
|
|
42924
|
-
while (applicationTasks.length > 0) {
|
|
42925
|
-
const task = applicationTasks.shift();
|
|
42926
|
-
const completion = await task.dispatch();
|
|
42927
|
-
const finalized = await completion.finalize();
|
|
42928
|
-
responses.push(...finalized.responses);
|
|
42929
|
-
applicationTasks.push(...finalized.applicationTasks);
|
|
42930
|
-
if (responses.length > MAX_SESSION_OUTPUTS)
|
|
42931
|
-
throw new RangeError("Too many Inline Protocol outputs");
|
|
42932
|
-
}
|
|
42933
|
-
return responses;
|
|
42934
|
-
}
|
|
42935
|
-
async receiveConcurrent(payload, receiveOptions = {}) {
|
|
42936
|
-
if (this.#destroyed)
|
|
42937
|
-
throw new InvalidEncryptedRecord;
|
|
42938
|
-
if (payload.length < 8 || payload.length > MAX_PACKET_BYTES)
|
|
42939
|
-
throw new InvalidEncryptedRecord;
|
|
42940
|
-
if (payload.slice(0, 8).every((byte) => byte === 0)) {
|
|
42941
|
-
return { responses: [await this.#receiveHandshake(payload)], applicationTasks: [] };
|
|
42942
|
-
}
|
|
42943
|
-
return this.#receiveEncrypted(payload, receiveOptions);
|
|
42944
|
-
}
|
|
42945
|
-
sendApplicationUpdate(payload) {
|
|
42946
|
-
if (this.#destroyed)
|
|
42947
|
-
throw new InvalidEncryptedRecord;
|
|
42948
|
-
return this.#encryptOutgoing(encodeInlineUpdate(payload), true, 3);
|
|
42949
|
-
}
|
|
42950
|
-
async#receiveHandshake(payload) {
|
|
42951
|
-
if (this.#authorization !== undefined)
|
|
42952
|
-
throw new InvalidEncryptedRecord;
|
|
42953
|
-
const request = decodeUnencryptedRecord(payload);
|
|
42954
|
-
const validation = validateInboundMessageId(request.messageId, "client", Math.floor(this.options.nowMilliseconds() / 1000));
|
|
42955
|
-
if (validation.kind === "bad")
|
|
42956
|
-
throw new InvalidEncryptedRecord;
|
|
42957
|
-
const result = await this.#handshake.receive(request.body);
|
|
42958
|
-
if (result.established) {
|
|
42959
|
-
this.#authorization = {
|
|
42960
|
-
...result.established,
|
|
42961
|
-
currentServerSalt: result.established.serverSalt
|
|
42962
|
-
};
|
|
42963
|
-
}
|
|
42964
|
-
return encodeUnencryptedRecord(this.#nextServerMessageId(1), result.response);
|
|
42965
|
-
}
|
|
42966
|
-
async#receiveEncrypted(payload, receiveOptions) {
|
|
42967
|
-
const authKeyId2 = payload.slice(0, 8);
|
|
42968
|
-
if (!this.#authorization || bytesToHex(this.#authorization.keyId) !== bytesToHex(authKeyId2)) {
|
|
42969
|
-
if (this.#sessionId !== undefined)
|
|
42970
|
-
throw new InvalidEncryptedRecord;
|
|
42971
|
-
const loaded = await this.options.authorizationKeys.load(authKeyId2);
|
|
42972
|
-
if (!loaded)
|
|
42973
|
-
throw new InlineProtocolAuthorizationInvalidated;
|
|
42974
|
-
this.#authorization = loaded;
|
|
42975
|
-
this.#sessionId = undefined;
|
|
42976
|
-
}
|
|
42977
|
-
const authorization = this.#authorization;
|
|
42978
|
-
let fields;
|
|
42979
|
-
let quickAckId;
|
|
42980
|
-
try {
|
|
42981
|
-
const decrypted = decryptRecordWithMetadata(payload, authorization.key, {
|
|
42982
|
-
direction: "client-to-server",
|
|
42983
|
-
sessionId: this.#sessionId,
|
|
42984
|
-
validServerSalts: new Set([
|
|
42985
|
-
authorization.currentServerSalt,
|
|
42986
|
-
...authorization.previousServerSalt === undefined ? [] : [authorization.previousServerSalt]
|
|
42987
|
-
]),
|
|
42988
|
-
nowSeconds: Math.floor(this.options.nowMilliseconds() / 1000)
|
|
42989
|
-
});
|
|
42990
|
-
fields = decrypted.fields;
|
|
42991
|
-
quickAckId = decrypted.quickAckId;
|
|
42992
|
-
} catch (error) {
|
|
42993
|
-
if (error instanceof RecoverableEncryptedRecordError && (this.#sessionId === undefined || this.#sessionId === error.fields.sessionId)) {
|
|
42994
|
-
this.#sessionId = error.fields.sessionId;
|
|
42995
|
-
const recovery = error.errorCode === 48 ? encodeBadServerSalt(error.fields.messageId, error.fields.sequenceNumber, 48, authorization.currentServerSalt) : encodeBadMsgNotification(error.fields.messageId, error.fields.sequenceNumber, error.errorCode);
|
|
42996
|
-
return {
|
|
42997
|
-
responses: [this.#encryptOutgoing(recovery, false, 1)],
|
|
42998
|
-
applicationTasks: []
|
|
42999
|
-
};
|
|
43000
|
-
}
|
|
43001
|
-
throw error;
|
|
43002
|
-
}
|
|
43003
|
-
const newSession = this.#sessionId === undefined;
|
|
43004
|
-
this.#sessionId ??= fields.sessionId;
|
|
43005
|
-
if (fields.sessionId !== this.#sessionId)
|
|
43006
|
-
throw new InvalidEncryptedRecord;
|
|
43007
|
-
const receivedIdsCheckpoint = this.#receivedIds.checkpoint();
|
|
43008
|
-
const receivedSequencesCheckpoint = this.#receivedSequences.checkpoint();
|
|
43009
|
-
let messages;
|
|
43010
|
-
if (serviceConstructor(fields.body) === ServiceConstructor.msgContainer) {
|
|
43011
|
-
const outerError = this.#validateLogical(fields, false, true);
|
|
43012
|
-
if (outerError !== undefined) {
|
|
43013
|
-
this.#receivedIds.restore(receivedIdsCheckpoint);
|
|
43014
|
-
this.#receivedSequences.restore(receivedSequencesCheckpoint);
|
|
43015
|
-
return {
|
|
43016
|
-
responses: [this.#encryptOutgoing(encodeBadMsgNotification(fields.messageId, fields.sequenceNumber, outerError), false, 1)],
|
|
43017
|
-
applicationTasks: []
|
|
43018
|
-
};
|
|
43019
|
-
}
|
|
43020
|
-
messages = this.#expandContainer(fields);
|
|
43021
|
-
} else {
|
|
43022
|
-
messages = [fields];
|
|
43023
|
-
}
|
|
43024
|
-
const prepared = [];
|
|
43025
|
-
for (const message of messages) {
|
|
43026
|
-
const originalBody = message.body;
|
|
43027
|
-
const unwrapped = this.#unwrapInvokeAfter(originalBody);
|
|
43028
|
-
const constructor3 = serviceConstructor(unwrapped.body);
|
|
43029
|
-
const contentRelated = unwrapped.wrapped || this.#isContentRelated(constructor3);
|
|
43030
|
-
const allowDuplicate = unwrapped.wrapped || constructor3 === BindingConstructor.bindTempAuthKey || constructor3 === ServiceConstructor.gzipPacked || constructor3 === ServiceConstructor.msgCopy || constructor3 === INLINE_INVOKE_CONSTRUCTOR;
|
|
43031
|
-
const duplicate = this.#receivedIds.has(message.messageId);
|
|
43032
|
-
const validation = this.#validateLogical(message, contentRelated, allowDuplicate);
|
|
43033
|
-
if (validation !== undefined) {
|
|
43034
|
-
this.#receivedIds.restore(receivedIdsCheckpoint);
|
|
43035
|
-
this.#receivedSequences.restore(receivedSequencesCheckpoint);
|
|
43036
|
-
return {
|
|
43037
|
-
responses: [this.#encryptOutgoing(encodeBadMsgNotification(message.messageId, message.sequenceNumber, validation), false, 1)],
|
|
43038
|
-
applicationTasks: []
|
|
43039
|
-
};
|
|
43040
|
-
}
|
|
43041
|
-
prepared.push({
|
|
43042
|
-
message: !unwrapped.wrapped ? message : {
|
|
43043
|
-
...message,
|
|
43044
|
-
body: unwrapped.body,
|
|
43045
|
-
authenticatedBody: message.authenticatedBody ?? originalBody
|
|
43046
|
-
},
|
|
43047
|
-
constructor: constructor3,
|
|
43048
|
-
contentRelated,
|
|
43049
|
-
duplicate,
|
|
43050
|
-
dependencies: unwrapped.dependencies
|
|
43051
|
-
});
|
|
43052
|
-
}
|
|
43053
|
-
receiveOptions.onQuickAck?.(quickAckId);
|
|
43054
|
-
const prefixResponses = [];
|
|
43055
|
-
if (newSession) {
|
|
43056
|
-
const firstContent = prepared.find((item) => item.contentRelated)?.message;
|
|
43057
|
-
if (firstContent) {
|
|
43058
|
-
prefixResponses.push(this.#encryptOutgoing(encodeNewSessionCreated(firstContent.messageId, readInt64LE(this.options.randomBytes(8), 0), authorization.currentServerSalt), true, 1));
|
|
43059
|
-
}
|
|
43060
|
-
}
|
|
43061
|
-
const responses = [];
|
|
43062
|
-
const applicationTasks = [];
|
|
43063
|
-
for (const item of prepared) {
|
|
43064
|
-
if (item.contentRelated)
|
|
43065
|
-
this.#acknowledgements.add(item.message.messageId);
|
|
43066
|
-
if (this.#dependenciesComplete(item.dependencies)) {
|
|
43067
|
-
const handled = await this.#completePreparedConcurrent(item);
|
|
43068
|
-
responses.push(...handled.responses);
|
|
43069
|
-
applicationTasks.push(...handled.applicationTasks);
|
|
43070
|
-
const deferred = await this.#drainDeferredConcurrent();
|
|
43071
|
-
responses.push(...deferred.responses);
|
|
43072
|
-
applicationTasks.push(...deferred.applicationTasks);
|
|
43073
|
-
} else {
|
|
43074
|
-
this.#defer(item);
|
|
43075
|
-
}
|
|
43076
|
-
if (prefixResponses.length + responses.length > MAX_SESSION_OUTPUTS) {
|
|
43077
|
-
throw new RangeError("Too many Inline Protocol outputs");
|
|
43078
|
-
}
|
|
43079
|
-
}
|
|
43080
|
-
const acknowledgements = this.#acknowledgements.drain();
|
|
43081
|
-
const acknowledgementResponses = acknowledgements.length > 0 ? [this.#encryptOutgoing(encodeMsgsAck(acknowledgements), false, 1)] : [];
|
|
43082
|
-
return {
|
|
43083
|
-
responses: [...prefixResponses, ...acknowledgementResponses, ...responses],
|
|
43084
|
-
applicationTasks
|
|
43085
|
-
};
|
|
43086
|
-
}
|
|
43087
|
-
#expandContainer(outer) {
|
|
43088
|
-
const children = decodeMessageContainer(outer.body);
|
|
43089
|
-
if (children.some((child) => child.messageId >= outer.messageId))
|
|
43090
|
-
throw new RangeError("Container ID must exceed child IDs");
|
|
43091
|
-
return children;
|
|
43092
|
-
}
|
|
43093
|
-
#unwrapInvokeAfter(body) {
|
|
43094
|
-
const dependencies = [];
|
|
43095
|
-
let query = body;
|
|
43096
|
-
for (let depth = 0;depth < MAX_INVOKE_AFTER_NESTING; depth += 1) {
|
|
43097
|
-
const constructor3 = serviceConstructor(query);
|
|
43098
|
-
if (constructor3 !== ServiceConstructor.invokeAfterMsg && constructor3 !== ServiceConstructor.invokeAfterMsgs) {
|
|
43099
|
-
return { body: query, dependencies, wrapped: dependencies.length > 0 || query !== body };
|
|
43100
|
-
}
|
|
43101
|
-
const wrapper = decodeInvokeAfter(query);
|
|
43102
|
-
dependencies.push(...wrapper.messageIds);
|
|
43103
|
-
if (dependencies.length > 8192)
|
|
43104
|
-
throw new RangeError("Too many invoke-after dependencies");
|
|
43105
|
-
query = wrapper.query;
|
|
43106
|
-
}
|
|
43107
|
-
throw new RangeError("Invoke-after nesting exceeds the limit");
|
|
43108
|
-
}
|
|
43109
|
-
#dependenciesComplete(dependencies) {
|
|
43110
|
-
return dependencies.every((messageId) => this.#completedIncoming.has(messageId));
|
|
43111
|
-
}
|
|
43112
|
-
#defer(item) {
|
|
43113
|
-
const existing = this.#deferredInvokeAfter.get(item.message.messageId);
|
|
43114
|
-
if (existing) {
|
|
43115
|
-
if (!equalBytes(existing.message.authenticatedBody ?? existing.message.body, item.message.authenticatedBody ?? item.message.body))
|
|
43116
|
-
throw new RangeError("Conflicting deferred invoke-after replay");
|
|
43117
|
-
return;
|
|
43118
|
-
}
|
|
43119
|
-
if (this.#deferredInvokeAfter.size >= MAX_DEFERRED_INVOKE_AFTER) {
|
|
43120
|
-
throw new RangeError("Too many deferred invoke-after queries");
|
|
43121
|
-
}
|
|
43122
|
-
this.#deferredInvokeAfter.set(item.message.messageId, item);
|
|
43123
|
-
}
|
|
43124
|
-
async#completePreparedConcurrent(item) {
|
|
43125
|
-
const handled = await this.#handleLogicalConcurrent(item.message, item);
|
|
43126
|
-
if (handled.completed)
|
|
43127
|
-
this.#markCompleted(item.message.messageId);
|
|
43128
|
-
return handled.result;
|
|
43129
|
-
}
|
|
43130
|
-
#markCompleted(messageId) {
|
|
43131
|
-
this.#completedIncoming.delete(messageId);
|
|
43132
|
-
this.#completedIncoming.set(messageId, true);
|
|
43133
|
-
if (this.#completedIncoming.size > MAX_COMPLETED_INCOMING_MESSAGES) {
|
|
43134
|
-
const oldest = this.#completedIncoming.keys().next().value;
|
|
43135
|
-
if (oldest !== undefined)
|
|
43136
|
-
this.#completedIncoming.delete(oldest);
|
|
43137
|
-
}
|
|
43138
|
-
}
|
|
43139
|
-
async#drainDeferredConcurrent() {
|
|
43140
|
-
const responses = [];
|
|
43141
|
-
const applicationTasks = [];
|
|
43142
|
-
let madeProgress = true;
|
|
43143
|
-
while (madeProgress) {
|
|
43144
|
-
madeProgress = false;
|
|
43145
|
-
for (const [messageId, item] of this.#deferredInvokeAfter) {
|
|
43146
|
-
if (!this.#dependenciesComplete(item.dependencies))
|
|
43147
|
-
continue;
|
|
43148
|
-
this.#deferredInvokeAfter.delete(messageId);
|
|
43149
|
-
const handled = await this.#completePreparedConcurrent(item);
|
|
43150
|
-
responses.push(...handled.responses);
|
|
43151
|
-
applicationTasks.push(...handled.applicationTasks);
|
|
43152
|
-
if (responses.length > MAX_SESSION_OUTPUTS)
|
|
43153
|
-
throw new RangeError("Too many Inline Protocol outputs");
|
|
43154
|
-
madeProgress = true;
|
|
43155
|
-
}
|
|
43156
|
-
}
|
|
43157
|
-
return { responses, applicationTasks };
|
|
43158
|
-
}
|
|
43159
|
-
async#handleLogicalConcurrent(message, prepared, completionMessageIds = [message.messageId]) {
|
|
43160
|
-
const constructor3 = prepared?.constructor ?? serviceConstructor(message.body);
|
|
43161
|
-
const contentRelated = prepared?.contentRelated ?? this.#isContentRelated(constructor3);
|
|
43162
|
-
const allowDuplicate = constructor3 === BindingConstructor.bindTempAuthKey || constructor3 === ServiceConstructor.gzipPacked || constructor3 === ServiceConstructor.msgCopy || constructor3 === INLINE_INVOKE_CONSTRUCTOR;
|
|
43163
|
-
const duplicate = prepared?.duplicate ?? this.#receivedIds.has(message.messageId);
|
|
43164
|
-
if (!prepared) {
|
|
43165
|
-
const validation = this.#validateLogical(message, contentRelated, allowDuplicate);
|
|
43166
|
-
if (validation !== undefined) {
|
|
43167
|
-
return {
|
|
43168
|
-
result: {
|
|
43169
|
-
responses: [this.#encryptOutgoing(encodeBadMsgNotification(message.messageId, message.sequenceNumber, validation), false, 1)],
|
|
43170
|
-
applicationTasks: []
|
|
43171
|
-
},
|
|
43172
|
-
completed: true
|
|
43173
|
-
};
|
|
43174
|
-
}
|
|
43175
|
-
if (contentRelated)
|
|
43176
|
-
this.#acknowledgements.add(message.messageId);
|
|
43177
|
-
}
|
|
43178
|
-
if (duplicate && !allowDuplicate) {
|
|
43179
|
-
return { result: { responses: [], applicationTasks: [] }, completed: true };
|
|
43180
|
-
}
|
|
43181
|
-
if (constructor3 === ServiceConstructor.gzipPacked) {
|
|
43182
|
-
const unpacked = decodeGzipPacked(message.body, this.options.gunzip);
|
|
43183
|
-
const unpackedMessage = {
|
|
43184
|
-
...message,
|
|
43185
|
-
body: unpacked,
|
|
43186
|
-
authenticatedBody: message.authenticatedBody ?? message.body
|
|
43187
|
-
};
|
|
43188
|
-
return this.#handleLogicalConcurrent(unpackedMessage, {
|
|
43189
|
-
message: unpackedMessage,
|
|
43190
|
-
constructor: serviceConstructor(unpacked),
|
|
43191
|
-
contentRelated,
|
|
43192
|
-
duplicate,
|
|
43193
|
-
dependencies: prepared?.dependencies ?? []
|
|
43194
|
-
}, completionMessageIds);
|
|
43195
|
-
}
|
|
43196
|
-
if (constructor3 === ServiceConstructor.msgCopy) {
|
|
43197
|
-
const copied = decodeMsgCopy(message.body);
|
|
43198
|
-
return this.#handleLogicalConcurrent({
|
|
43199
|
-
...copied,
|
|
43200
|
-
authenticatedBody: copied.body
|
|
43201
|
-
}, undefined, [...completionMessageIds, copied.messageId]);
|
|
43202
|
-
}
|
|
43203
|
-
if (constructor3 === INLINE_INVOKE_CONSTRUCTOR) {
|
|
43204
|
-
return this.#acceptApplication(message, completionMessageIds);
|
|
43205
|
-
}
|
|
43206
|
-
return {
|
|
43207
|
-
result: {
|
|
43208
|
-
responses: await this.#handleLogical(message, prepared),
|
|
43209
|
-
applicationTasks: []
|
|
43210
|
-
},
|
|
43211
|
-
completed: true
|
|
43212
|
-
};
|
|
43213
|
-
}
|
|
43214
|
-
async#handleLogical(message, prepared) {
|
|
43215
|
-
const constructor3 = prepared?.constructor ?? serviceConstructor(message.body);
|
|
43216
|
-
const contentRelated = prepared?.contentRelated ?? this.#isContentRelated(constructor3);
|
|
43217
|
-
const allowDuplicate = constructor3 === BindingConstructor.bindTempAuthKey || constructor3 === ServiceConstructor.gzipPacked || constructor3 === ServiceConstructor.msgCopy || constructor3 === INLINE_INVOKE_CONSTRUCTOR;
|
|
43218
|
-
const duplicate = prepared?.duplicate ?? this.#receivedIds.has(message.messageId);
|
|
43219
|
-
if (!prepared) {
|
|
43220
|
-
const validation = this.#validateLogical(message, contentRelated, allowDuplicate);
|
|
43221
|
-
if (validation !== undefined) {
|
|
43222
|
-
return [this.#encryptOutgoing(encodeBadMsgNotification(message.messageId, message.sequenceNumber, validation), false, 1)];
|
|
43223
|
-
}
|
|
43224
|
-
}
|
|
43225
|
-
if (contentRelated)
|
|
43226
|
-
this.#acknowledgements.add(message.messageId);
|
|
43227
|
-
if (duplicate && !allowDuplicate)
|
|
43228
|
-
return [];
|
|
43229
|
-
switch (constructor3) {
|
|
43230
|
-
case ServiceConstructor.msgsAck:
|
|
43231
|
-
this.#pending.acknowledge(decodeMsgsAck(message.body));
|
|
43232
|
-
return [];
|
|
43233
|
-
case ServiceConstructor.msgResendReq: {
|
|
43234
|
-
const messageIds = decodeMsgResendReq(message.body);
|
|
43235
|
-
const pendingMessages = this.#pending.resend(messageIds);
|
|
43236
|
-
if (pendingMessages.length !== messageIds.length) {
|
|
43237
|
-
return [this.#encryptOutgoing(encodeMsgsStateInfo(message.messageId, this.#pending.state(messageIds)), false, 1)];
|
|
43238
|
-
}
|
|
43239
|
-
return pendingMessages.map((pending) => this.#encryptOutgoing(pending.body, pending.sequenceNumber % 2 === 1, 1, pending.messageId, pending.sequenceNumber));
|
|
43240
|
-
}
|
|
43241
|
-
case ServiceConstructor.msgsStateReq: {
|
|
43242
|
-
const ids = decodeMsgsStateReq(message.body);
|
|
43243
|
-
const states = Uint8Array.from(ids, (id) => this.#receivedIds.has(id) ? 4 : 1);
|
|
43244
|
-
return [this.#encryptOutgoing(encodeMsgsStateInfo(message.messageId, states), false, 1)];
|
|
43245
|
-
}
|
|
43246
|
-
case ServiceConstructor.msgsAllInfo: {
|
|
43247
|
-
const { messageIds, states } = decodeMsgsAllInfo(message.body);
|
|
43248
|
-
this.#pending.acknowledge(messageIds.filter((_, index) => {
|
|
43249
|
-
const state = states[index];
|
|
43250
|
-
return (state & 7) === 4 || (state & 128) !== 0;
|
|
43251
|
-
}));
|
|
43252
|
-
return [];
|
|
43253
|
-
}
|
|
43254
|
-
case ServiceConstructor.ping:
|
|
43255
|
-
case ServiceConstructor.pingDelayDisconnect: {
|
|
43256
|
-
if (message.body.length !== (constructor3 === ServiceConstructor.ping ? 12 : 16))
|
|
43257
|
-
throw new RangeError("Invalid ping");
|
|
43258
|
-
return [this.#encryptOutgoing(encodePong(message.messageId, readInt64LE(message.body, 4)), false, 1)];
|
|
43259
|
-
}
|
|
43260
|
-
case ServiceConstructor.httpWait:
|
|
43261
|
-
decodeHttpWait(message.body);
|
|
43262
|
-
if (this.options.carrierProfile !== "http") {
|
|
43263
|
-
throw new RangeError("HTTP wait is invalid outside the HTTP carrier profile");
|
|
43264
|
-
}
|
|
43265
|
-
return [];
|
|
43266
|
-
case ServiceConstructor.rpcDropAnswer: {
|
|
43267
|
-
const requestMessageId = decodeRpcDropAnswer(message.body);
|
|
43268
|
-
const dropped = this.#pending.dropRpcResult(requestMessageId);
|
|
43269
|
-
if (dropped) {
|
|
43270
|
-
await this.options.replay.forgetAnswer({
|
|
43271
|
-
authKeyId: this.#authorization.keyId,
|
|
43272
|
-
sessionId: this.#sessionId,
|
|
43273
|
-
messageId: requestMessageId,
|
|
43274
|
-
forgottenResultBody: encodeRpcResult(requestMessageId, encodeRpcDropAnswerResult({ kind: "unknown" }))
|
|
43275
|
-
});
|
|
43276
|
-
}
|
|
43277
|
-
const status = dropped ? {
|
|
43278
|
-
kind: "dropped",
|
|
43279
|
-
messageId: dropped.messageId,
|
|
43280
|
-
sequenceNumber: dropped.sequenceNumber,
|
|
43281
|
-
bytes: dropped.body.length
|
|
43282
|
-
} : await this.options.replay.dropAnswer({
|
|
43283
|
-
authKeyId: this.#authorization.keyId,
|
|
43284
|
-
sessionId: this.#sessionId,
|
|
43285
|
-
messageId: requestMessageId,
|
|
43286
|
-
runningResultBody: encodeRpcResult(requestMessageId, encodeRpcDropAnswerResult({ kind: "running" }))
|
|
43287
|
-
}) === "running" ? { kind: "running" } : { kind: "unknown" };
|
|
43288
|
-
if (status.kind === "running")
|
|
43289
|
-
this.#droppedApplicationAnswers.add(requestMessageId);
|
|
43290
|
-
return [this.#encryptOutgoing(encodeRpcResult(message.messageId, encodeRpcDropAnswerResult(status)), true, 1)];
|
|
43291
|
-
}
|
|
43292
|
-
case ServiceConstructor.gzipPacked: {
|
|
43293
|
-
const unpacked = decodeGzipPacked(message.body, this.options.gunzip);
|
|
43294
|
-
return this.#handleLogical({
|
|
43295
|
-
...message,
|
|
43296
|
-
body: unpacked,
|
|
43297
|
-
authenticatedBody: message.authenticatedBody ?? message.body
|
|
43298
|
-
});
|
|
43299
|
-
}
|
|
43300
|
-
case ServiceConstructor.msgCopy: {
|
|
43301
|
-
const copied = decodeMsgCopy(message.body);
|
|
43302
|
-
return this.#handleLogical({
|
|
43303
|
-
...copied,
|
|
43304
|
-
authenticatedBody: copied.body
|
|
43305
|
-
});
|
|
43306
|
-
}
|
|
43307
|
-
case ServiceConstructor.getFutureSalts: {
|
|
43308
|
-
decodeGetFutureSalts(message.body);
|
|
43309
|
-
const now = Math.floor(this.options.nowMilliseconds() / 1000);
|
|
43310
|
-
const newSalt = readInt64LE(this.options.randomBytes(8), 0);
|
|
43311
|
-
const response = this.#encryptOutgoing(encodeFutureSalts(message.messageId, now, [{
|
|
43312
|
-
validSince: now,
|
|
43313
|
-
validUntil: now + 30 * 60,
|
|
43314
|
-
salt: newSalt
|
|
43315
|
-
}]), true, 1);
|
|
43316
|
-
if (!await this.options.authorizationKeys.rotateServerSalt(this.#authorization.keyId, newSalt)) {
|
|
43317
|
-
throw new RangeError("Authorization key disappeared during salt rotation");
|
|
43318
|
-
}
|
|
43319
|
-
this.#authorization.previousServerSalt = this.#authorization.currentServerSalt;
|
|
43320
|
-
this.#authorization.currentServerSalt = newSalt;
|
|
43321
|
-
return [response];
|
|
43322
|
-
}
|
|
43323
|
-
case ServiceConstructor.destroySession: {
|
|
43324
|
-
const target = decodeDestroySession(message.body);
|
|
43325
|
-
const found = target === this.#sessionId;
|
|
43326
|
-
const response = this.#encryptOutgoing(encodeDestroySessionResult(target, found), true, 1);
|
|
43327
|
-
if (found)
|
|
43328
|
-
this.#destroyed = true;
|
|
43329
|
-
return [response];
|
|
43330
|
-
}
|
|
43331
|
-
case ServiceConstructor.destroyAuthKey: {
|
|
43332
|
-
if (message.body.length !== 4)
|
|
43333
|
-
throw new RangeError("Invalid destroy-auth-key request");
|
|
43334
|
-
const revoked = await this.options.authorizationKeys.revoke(this.#authorization.keyId);
|
|
43335
|
-
const response = this.#encryptOutgoing(encodeDestroyAuthKeyResult(revoked ? "ok" : "none"), true, 1);
|
|
43336
|
-
if (revoked)
|
|
43337
|
-
this.#destroyed = true;
|
|
43338
|
-
return [response];
|
|
43339
|
-
}
|
|
43340
|
-
case BindingConstructor.bindTempAuthKey:
|
|
43341
|
-
return [await this.#bindTemporary(message)];
|
|
43342
|
-
default:
|
|
43343
|
-
return this.#dispatchApplication(message);
|
|
43344
|
-
}
|
|
43345
|
-
}
|
|
43346
|
-
async#bindTemporary(message) {
|
|
43347
|
-
const temporary = this.#authorization;
|
|
43348
|
-
if (!temporary?.temporary || temporary.binding || temporary.expiresAt === undefined || this.#sessionId === undefined) {
|
|
43349
|
-
throw new RangeError("Temporary-key binding is not allowed");
|
|
43350
|
-
}
|
|
43351
|
-
const request = decodeBindTempAuthKey(message.body);
|
|
43352
|
-
const permanentId = int64LE(request.permanentAuthKeyId);
|
|
43353
|
-
const permanent = await this.options.authorizationKeys.load(permanentId);
|
|
43354
|
-
if (!permanent || permanent.temporary || !permanent.authorized) {
|
|
43355
|
-
this.#destroyed = true;
|
|
43356
|
-
throw new InlineProtocolAuthorizationInvalidated;
|
|
43357
|
-
}
|
|
43358
|
-
verifyTemporaryKeyBindingProof({
|
|
43359
|
-
encryptedMessage: request.encryptedMessage,
|
|
43360
|
-
permanentAuthKey: permanent.key,
|
|
43361
|
-
outerPermanentAuthKeyId: request.permanentAuthKeyId,
|
|
43362
|
-
outerTemporaryAuthKeyId: new DataView(temporary.keyId.buffer, temporary.keyId.byteOffset, 8).getBigInt64(0, true),
|
|
43363
|
-
outerTemporarySessionId: this.#sessionId,
|
|
43364
|
-
outerMessageId: message.messageId,
|
|
43365
|
-
outerNonce: request.nonce,
|
|
43366
|
-
outerExpiresAt: request.expiresAt,
|
|
43367
|
-
temporaryKeyExpiresAt: temporary.expiresAt,
|
|
43368
|
-
nowSeconds: Math.floor(this.options.nowMilliseconds() / 1000)
|
|
43369
|
-
});
|
|
43370
|
-
const result = await this.options.authorizationKeys.bindTemporary({
|
|
43371
|
-
temporaryAuthKeyId: temporary.keyId,
|
|
43372
|
-
permanentAuthKeyId: permanent.keyId,
|
|
43373
|
-
temporarySessionId: this.#sessionId,
|
|
43374
|
-
nonce: request.nonce,
|
|
43375
|
-
expiresAt: request.expiresAt,
|
|
43376
|
-
userId: permanent.authorized.userId,
|
|
43377
|
-
accountSessionId: permanent.authorized.accountSessionId
|
|
43378
|
-
});
|
|
43379
|
-
if (result === "conflict")
|
|
43380
|
-
throw new RangeError("Temporary-key binding conflicts");
|
|
43381
|
-
temporary.binding = {
|
|
43382
|
-
permanentAuthKeyId: permanent.keyId.slice(),
|
|
43383
|
-
temporarySessionId: this.#sessionId,
|
|
43384
|
-
nonce: request.nonce,
|
|
43385
|
-
expiresAt: request.expiresAt,
|
|
43386
|
-
userId: permanent.authorized.userId,
|
|
43387
|
-
accountSessionId: permanent.authorized.accountSessionId
|
|
43388
|
-
};
|
|
43389
|
-
return this.#encryptOutgoing(encodeRpcResult(message.messageId, uint32LE(BOOL_TRUE)), true, 1);
|
|
43390
|
-
}
|
|
43391
|
-
async#acceptApplication(message, completionMessageIds = [message.messageId]) {
|
|
43392
|
-
const activeAuthorization = this.#authorization;
|
|
43393
|
-
const sessionId = this.#sessionId;
|
|
43394
|
-
if (!activeAuthorization || sessionId === undefined)
|
|
43395
|
-
throw new InvalidEncryptedRecord;
|
|
43396
|
-
const authorization = await this.options.authorizationKeys.load(activeAuthorization.keyId);
|
|
43397
|
-
if (!authorization) {
|
|
43398
|
-
this.#destroyed = true;
|
|
43399
|
-
throw new InlineProtocolAuthorizationInvalidated;
|
|
43400
|
-
}
|
|
43401
|
-
if (!equalBytes(authorization.keyId, activeAuthorization.keyId) || this.#sessionId !== sessionId) {
|
|
43402
|
-
throw new InvalidEncryptedRecord;
|
|
43403
|
-
}
|
|
43404
|
-
this.#authorization = authorization;
|
|
43405
|
-
if (authorization.temporary && !authorization.binding) {
|
|
43406
|
-
throw new RangeError("Authorization-key state does not permit application dispatch");
|
|
43407
|
-
}
|
|
43408
|
-
const application = decodeInlineApplicationObject(message.body);
|
|
43409
|
-
if (application.kind !== "invoke" || application.layer !== INLINE_REALTIME_LAYER) {
|
|
43410
|
-
throw new RangeError("Invalid Inline application request");
|
|
43411
|
-
}
|
|
43412
|
-
const replay = await this.options.replay.claim({
|
|
43413
|
-
authKeyId: authorization.keyId,
|
|
43414
|
-
sessionId,
|
|
43415
|
-
messageId: message.messageId,
|
|
43416
|
-
authenticatedBody: message.authenticatedBody ?? message.body
|
|
43417
|
-
});
|
|
43418
|
-
if (replay.kind === "digest_mismatch")
|
|
43419
|
-
throw new RangeError("Replay digest mismatch");
|
|
43420
|
-
if (replay.kind === "completed") {
|
|
43421
|
-
return {
|
|
43422
|
-
result: {
|
|
43423
|
-
responses: [this.#encryptOutgoing(replay.resultBody, true, 1)],
|
|
43424
|
-
applicationTasks: []
|
|
43425
|
-
},
|
|
43426
|
-
completed: true
|
|
43427
|
-
};
|
|
43428
|
-
}
|
|
43429
|
-
if (replay.kind === "in_flight") {
|
|
43430
|
-
return {
|
|
43431
|
-
result: {
|
|
43432
|
-
responses: [this.#encryptOutgoing(encodeMsgsStateInfo(message.messageId, Uint8Array.of(4)), false, 1)],
|
|
43433
|
-
applicationTasks: []
|
|
43434
|
-
},
|
|
43435
|
-
completed: false
|
|
43436
|
-
};
|
|
43437
|
-
}
|
|
43438
|
-
if (this.#inFlightApplications.size >= MAX_IN_FLIGHT_APPLICATIONS) {
|
|
43439
|
-
const resultBody = encodeRpcResult(message.messageId, encodeRpcError(503, "Realtime application capacity exceeded"));
|
|
43440
|
-
const completion = await this.options.replay.complete({
|
|
43441
|
-
authKeyId: authorization.keyId,
|
|
43442
|
-
sessionId,
|
|
43443
|
-
messageId: message.messageId,
|
|
43444
|
-
resultBody
|
|
43445
|
-
});
|
|
43446
|
-
return {
|
|
43447
|
-
result: {
|
|
43448
|
-
responses: [this.#encryptOutgoing(completion.kind === "completed" ? resultBody : completion.resultBody, true, 1)],
|
|
43449
|
-
applicationTasks: []
|
|
43450
|
-
},
|
|
43451
|
-
completed: true
|
|
43452
|
-
};
|
|
43453
|
-
}
|
|
43454
|
-
const applicationAuthorization = {
|
|
43455
|
-
authKeyId: authorization.keyId.slice(),
|
|
43456
|
-
permanentAuthKeyId: authorization.temporary ? authorization.binding?.permanentAuthKeyId.slice() : authorization.keyId.slice(),
|
|
43457
|
-
permanent: !authorization.temporary,
|
|
43458
|
-
temporaryBound: authorization.binding !== undefined,
|
|
43459
|
-
userId: authorization.temporary ? authorization.binding?.userId : authorization.authorized?.userId,
|
|
43460
|
-
accountSessionId: authorization.temporary ? authorization.binding?.accountSessionId : authorization.authorized?.accountSessionId
|
|
43461
|
-
};
|
|
43462
|
-
this.#inFlightApplications.add(message.messageId);
|
|
43463
|
-
let didDispatch = false;
|
|
43464
|
-
const task = {
|
|
43465
|
-
messageId: message.messageId,
|
|
43466
|
-
dispatch: async () => {
|
|
43467
|
-
if (didDispatch)
|
|
43468
|
-
throw new RangeError("Application task was already dispatched");
|
|
43469
|
-
didDispatch = true;
|
|
43470
|
-
const updates = [];
|
|
43471
|
-
let updateBytes = 0;
|
|
43472
|
-
const applicationUpdateReleases = [];
|
|
43473
|
-
let acceptingUpdates = true;
|
|
43474
|
-
let executionStarted = false;
|
|
43475
|
-
const controller = new AbortController;
|
|
43476
|
-
let timeout;
|
|
43477
|
-
let applicationRelease;
|
|
43478
|
-
const makeSettlement = (dispatched, includeResult) => {
|
|
43479
|
-
let didFinalize = false;
|
|
43480
|
-
return {
|
|
43481
|
-
messageId: message.messageId,
|
|
43482
|
-
finalize: async () => {
|
|
43483
|
-
if (didFinalize)
|
|
43484
|
-
throw new RangeError("Application completion was already finalized");
|
|
43485
|
-
didFinalize = true;
|
|
43486
|
-
return this.#finalizeApplication({
|
|
43487
|
-
authKeyId: authorization.keyId.slice(),
|
|
43488
|
-
sessionId,
|
|
43489
|
-
messageId: message.messageId,
|
|
43490
|
-
completionMessageIds,
|
|
43491
|
-
dispatched,
|
|
43492
|
-
updates,
|
|
43493
|
-
includeResult,
|
|
43494
|
-
applicationRelease,
|
|
43495
|
-
applicationUpdateReleases
|
|
43496
|
-
});
|
|
43497
|
-
}
|
|
43498
|
-
};
|
|
43499
|
-
};
|
|
43500
|
-
if (this.options.tryAcquireApplication) {
|
|
43501
|
-
applicationRelease = this.options.tryAcquireApplication(applicationAuthorization);
|
|
43502
|
-
if (!applicationRelease) {
|
|
43503
|
-
acceptingUpdates = false;
|
|
43504
|
-
return makeSettlement({
|
|
43505
|
-
kind: "error",
|
|
43506
|
-
code: 503,
|
|
43507
|
-
message: "Realtime application capacity exceeded"
|
|
43508
|
-
}, true);
|
|
43509
|
-
}
|
|
43510
|
-
}
|
|
43511
|
-
const applicationDispatch = (async () => {
|
|
43512
|
-
try {
|
|
43513
|
-
const dispatched = await this.options.application.dispatch({
|
|
43514
|
-
payload: application.payload.slice(),
|
|
43515
|
-
authorization: applicationAuthorization,
|
|
43516
|
-
messageId: message.messageId,
|
|
43517
|
-
sessionId,
|
|
43518
|
-
signal: controller.signal,
|
|
43519
|
-
markExecutionStarted: () => {
|
|
43520
|
-
executionStarted = true;
|
|
43521
|
-
},
|
|
43522
|
-
sendUpdate: (payload) => {
|
|
43523
|
-
if (!acceptingUpdates)
|
|
43524
|
-
return;
|
|
43525
|
-
if (updates.length >= MAX_SESSION_OUTPUTS - 1 || updateBytes + payload.length > MAX_PACKET_BYTES) {
|
|
43526
|
-
throw new InlineProtocolApplicationOutputOverloaded;
|
|
43527
|
-
}
|
|
43528
|
-
const updateRelease = this.options.tryReserveApplicationUpdateBytes?.(payload.length);
|
|
43529
|
-
if (this.options.tryReserveApplicationUpdateBytes && !updateRelease) {
|
|
43530
|
-
throw new InlineProtocolApplicationOutputOverloaded;
|
|
43531
|
-
}
|
|
43532
|
-
try {
|
|
43533
|
-
const copy = payload.slice();
|
|
43534
|
-
updates.push(copy);
|
|
43535
|
-
updateBytes += copy.length;
|
|
43536
|
-
if (updateRelease)
|
|
43537
|
-
applicationUpdateReleases.push(updateRelease);
|
|
43538
|
-
} catch (error) {
|
|
43539
|
-
updateRelease?.();
|
|
43540
|
-
throw error;
|
|
43541
|
-
}
|
|
43542
|
-
}
|
|
43543
|
-
});
|
|
43544
|
-
return { kind: "settled", dispatched };
|
|
43545
|
-
} catch (error) {
|
|
43546
|
-
updates.length = 0;
|
|
43547
|
-
updateBytes = 0;
|
|
43548
|
-
for (const release of applicationUpdateReleases.splice(0))
|
|
43549
|
-
release();
|
|
43550
|
-
return {
|
|
43551
|
-
kind: "settled",
|
|
43552
|
-
dispatched: error instanceof InlineProtocolApplicationOutputOverloaded ? {
|
|
43553
|
-
kind: "error",
|
|
43554
|
-
code: 504,
|
|
43555
|
-
message: "Realtime application output capacity exceeded; commit outcome is unknown"
|
|
43556
|
-
} : controller.signal.aborted ? {
|
|
43557
|
-
kind: "error",
|
|
43558
|
-
code: executionStarted ? 504 : 503,
|
|
43559
|
-
message: executionStarted ? "Realtime application deadline exceeded; commit outcome is unknown" : "Realtime application deadline exceeded before execution"
|
|
43560
|
-
} : { kind: "error", code: 500, message: "Internal server error" }
|
|
43561
|
-
};
|
|
43562
|
-
}
|
|
43563
|
-
})();
|
|
43564
|
-
const applicationDeadline = new Promise((resolve) => {
|
|
43565
|
-
timeout = setTimeout(() => {
|
|
43566
|
-
controller.abort();
|
|
43567
|
-
resolve({ kind: "deadline" });
|
|
43568
|
-
}, this.options.applicationTimeoutMs ?? DEFAULT_APPLICATION_TIMEOUT_MS);
|
|
43569
|
-
});
|
|
43570
|
-
const first = await Promise.race([applicationDispatch, applicationDeadline]);
|
|
43571
|
-
if (timeout !== undefined)
|
|
43572
|
-
clearTimeout(timeout);
|
|
43573
|
-
if (first.kind === "settled") {
|
|
43574
|
-
acceptingUpdates = false;
|
|
43575
|
-
return makeSettlement(first.dispatched, true);
|
|
43576
|
-
}
|
|
43577
|
-
let didFinalizeDeadline = false;
|
|
43578
|
-
return {
|
|
43579
|
-
messageId: message.messageId,
|
|
43580
|
-
settlement: applicationDispatch.then(({ dispatched }) => {
|
|
43581
|
-
acceptingUpdates = false;
|
|
43582
|
-
return makeSettlement(dispatched, false);
|
|
43583
|
-
}),
|
|
43584
|
-
finalize: async () => {
|
|
43585
|
-
if (didFinalizeDeadline)
|
|
43586
|
-
throw new RangeError("Application deadline was already finalized");
|
|
43587
|
-
didFinalizeDeadline = true;
|
|
43588
|
-
return this.#finalizeApplicationDeadline({
|
|
43589
|
-
authKeyId: authorization.keyId.slice(),
|
|
43590
|
-
sessionId,
|
|
43591
|
-
messageId: message.messageId,
|
|
43592
|
-
executionStarted
|
|
43593
|
-
});
|
|
43594
|
-
}
|
|
43595
|
-
};
|
|
43596
|
-
}
|
|
43597
|
-
};
|
|
43598
|
-
return {
|
|
43599
|
-
result: { responses: [], applicationTasks: [task] },
|
|
43600
|
-
completed: false
|
|
43601
|
-
};
|
|
43602
|
-
}
|
|
43603
|
-
async#finalizeApplication(input) {
|
|
43604
|
-
try {
|
|
43605
|
-
const resultObject = input.dispatched.kind === "result" ? encodeInlineResult(input.dispatched.payload) : encodeRpcError(input.dispatched.code, input.dispatched.message);
|
|
43606
|
-
const resultBody = encodeRpcResult(input.messageId, resultObject);
|
|
43607
|
-
const replayResultBody = input.dispatched.kind === "result" && input.dispatched.replayPayload ? encodeRpcResult(input.messageId, encodeInlineResult(input.dispatched.replayPayload)) : resultBody;
|
|
43608
|
-
const completion = await this.options.replay.complete({
|
|
43609
|
-
authKeyId: input.authKeyId,
|
|
43610
|
-
sessionId: input.sessionId,
|
|
43611
|
-
messageId: input.messageId,
|
|
43612
|
-
resultBody: replayResultBody
|
|
43613
|
-
});
|
|
43614
|
-
const terminateAuthorization = input.dispatched.terminateAuthorization === true;
|
|
43615
|
-
if (terminateAuthorization) {
|
|
43616
|
-
if (this.#destroyed || this.#sessionId !== input.sessionId || !this.#authorization || !equalBytes(this.#authorization.keyId, input.authKeyId)) {
|
|
43617
|
-
return { responses: [], applicationTasks: [] };
|
|
43618
|
-
}
|
|
43619
|
-
const answerDropped2 = this.#droppedApplicationAnswers.delete(input.messageId);
|
|
43620
|
-
const responses2 = input.includeResult && !answerDropped2 ? [this.#encryptOutgoing(completion.kind === "completed" ? resultBody : completion.resultBody, true, 1)] : [];
|
|
43621
|
-
for (const messageId of new Set(input.completionMessageIds))
|
|
43622
|
-
this.#markCompleted(messageId);
|
|
43623
|
-
this.#deferredInvokeAfter.clear();
|
|
43624
|
-
this.#destroyed = true;
|
|
43625
|
-
return { responses: responses2, applicationTasks: [] };
|
|
43626
|
-
}
|
|
43627
|
-
const refreshed = await this.options.authorizationKeys.load(input.authKeyId);
|
|
43628
|
-
if (!refreshed) {
|
|
43629
|
-
this.#destroyed = true;
|
|
43630
|
-
return { responses: [], applicationTasks: [] };
|
|
43631
|
-
}
|
|
43632
|
-
if (this.#destroyed || this.#sessionId !== input.sessionId || !this.#authorization || !equalBytes(this.#authorization.keyId, input.authKeyId)) {
|
|
43633
|
-
return { responses: [], applicationTasks: [] };
|
|
43634
|
-
}
|
|
43635
|
-
this.#authorization = refreshed;
|
|
43636
|
-
const answerDropped = this.#droppedApplicationAnswers.delete(input.messageId);
|
|
43637
|
-
const responses = input.includeResult && !answerDropped ? [this.#encryptOutgoing(completion.kind === "completed" ? resultBody : completion.resultBody, true, 1)] : [];
|
|
43638
|
-
if (completion.kind === "completed") {
|
|
43639
|
-
for (const update of input.updates)
|
|
43640
|
-
responses.push(this.sendApplicationUpdate(update));
|
|
43641
|
-
}
|
|
43642
|
-
for (const messageId of new Set(input.completionMessageIds))
|
|
43643
|
-
this.#markCompleted(messageId);
|
|
43644
|
-
const deferred = await this.#drainDeferredConcurrent();
|
|
43645
|
-
const acknowledgements = this.#acknowledgements.drain();
|
|
43646
|
-
if (acknowledgements.length > 0) {
|
|
43647
|
-
responses.push(this.#encryptOutgoing(encodeMsgsAck(acknowledgements), false, 1));
|
|
43648
|
-
}
|
|
43649
|
-
responses.push(...deferred.responses);
|
|
43650
|
-
return { responses, applicationTasks: deferred.applicationTasks };
|
|
43651
|
-
} finally {
|
|
43652
|
-
this.#droppedApplicationAnswers.delete(input.messageId);
|
|
43653
|
-
for (const release of input.applicationUpdateReleases.splice(0))
|
|
43654
|
-
release();
|
|
43655
|
-
input.applicationRelease?.();
|
|
43656
|
-
this.#inFlightApplications.delete(input.messageId);
|
|
43657
|
-
}
|
|
43658
|
-
}
|
|
43659
|
-
async#finalizeApplicationDeadline(input) {
|
|
43660
|
-
if (this.#destroyed || this.#sessionId !== input.sessionId || !this.#authorization || !equalBytes(this.#authorization.keyId, input.authKeyId)) {
|
|
43661
|
-
return { responses: [], applicationTasks: [] };
|
|
43662
|
-
}
|
|
43663
|
-
const deadlineResultBody = encodeRpcResult(input.messageId, input.executionStarted ? encodeRpcError(504, "Realtime application deadline exceeded; commit outcome is unknown") : encodeRpcError(503, "Realtime application deadline exceeded before execution"));
|
|
43664
|
-
const resultBody = input.executionStarted ? deadlineResultBody : await this.options.replay.complete({
|
|
43665
|
-
authKeyId: input.authKeyId,
|
|
43666
|
-
sessionId: input.sessionId,
|
|
43667
|
-
messageId: input.messageId,
|
|
43668
|
-
resultBody: deadlineResultBody
|
|
43669
|
-
}).then((completion) => completion.kind === "completed" ? deadlineResultBody : completion.resultBody);
|
|
43670
|
-
const answerDropped = this.#droppedApplicationAnswers.delete(input.messageId);
|
|
43671
|
-
return {
|
|
43672
|
-
responses: answerDropped ? [] : [this.#encryptOutgoing(resultBody, true, 1)],
|
|
43673
|
-
applicationTasks: []
|
|
43674
|
-
};
|
|
43675
|
-
}
|
|
43676
|
-
async#dispatchApplication(message) {
|
|
43677
|
-
const accepted = await this.#acceptApplication(message);
|
|
43678
|
-
const responses = [...accepted.result.responses];
|
|
43679
|
-
const tasks = [...accepted.result.applicationTasks];
|
|
43680
|
-
while (tasks.length > 0) {
|
|
43681
|
-
const completion = await tasks.shift().dispatch();
|
|
43682
|
-
const finalized = await completion.finalize();
|
|
43683
|
-
responses.push(...finalized.responses);
|
|
43684
|
-
tasks.push(...finalized.applicationTasks);
|
|
43685
|
-
if (completion.settlement) {
|
|
43686
|
-
const settlement = await completion.settlement;
|
|
43687
|
-
const settled = await settlement.finalize();
|
|
43688
|
-
responses.push(...settled.responses);
|
|
43689
|
-
tasks.push(...settled.applicationTasks);
|
|
43690
|
-
}
|
|
43691
|
-
}
|
|
43692
|
-
return responses;
|
|
43693
|
-
}
|
|
43694
|
-
#validateLogical(message, contentRelated, allowDuplicate = false) {
|
|
43695
|
-
const time = validateInboundMessageId(message.messageId, "client", Math.floor(this.options.nowMilliseconds() / 1000));
|
|
43696
|
-
if (time.kind === "bad")
|
|
43697
|
-
return time.errorCode;
|
|
43698
|
-
if (this.#receivedIds.has(message.messageId))
|
|
43699
|
-
return allowDuplicate ? undefined : 20;
|
|
43700
|
-
if (!this.#receivedIds.claim(message.messageId))
|
|
43701
|
-
return 20;
|
|
43702
|
-
return this.#receivedSequences.validate(message.messageId, message.sequenceNumber, contentRelated);
|
|
43703
|
-
}
|
|
43704
|
-
#isContentRelated(constructor3) {
|
|
43705
|
-
return !NON_CONTENT_CONSTRUCTORS.has(constructor3);
|
|
43706
|
-
}
|
|
43707
|
-
#encryptOutgoing(body, contentRelated, modulo, fixedMessageId, fixedSequenceNumber) {
|
|
43708
|
-
const authorization = this.#authorization;
|
|
43709
|
-
const sessionId = this.#sessionId;
|
|
43710
|
-
if (!authorization || sessionId === undefined)
|
|
43711
|
-
throw new InvalidEncryptedRecord;
|
|
43712
|
-
const messageId = fixedMessageId ?? this.#nextServerMessageId(modulo);
|
|
43713
|
-
const sequenceNumber = fixedSequenceNumber ?? (fixedMessageId === undefined ? this.#sequenceNumbers.next(contentRelated) : contentRelated ? 1 : 0);
|
|
43714
|
-
const paddingLength = 12 + (16 - (32 + body.length + 12) % 16) % 16;
|
|
43715
|
-
const record = encryptRecord(authorization.key, "server-to-client", {
|
|
43716
|
-
serverSalt: authorization.currentServerSalt,
|
|
43717
|
-
sessionId,
|
|
43718
|
-
messageId,
|
|
43719
|
-
sequenceNumber,
|
|
43720
|
-
body
|
|
43721
|
-
}, this.options.randomBytes(paddingLength));
|
|
43722
|
-
if (contentRelated && fixedMessageId === undefined)
|
|
43723
|
-
this.#pending.retain({ messageId, sequenceNumber, body });
|
|
43724
|
-
return record;
|
|
43725
|
-
}
|
|
43726
|
-
#nextServerMessageId(modulo) {
|
|
43727
|
-
const random = this.options.randomBytes(4);
|
|
43728
|
-
if (random.length !== 4)
|
|
43729
|
-
throw new RangeError("CSPRNG returned invalid message-ID randomness");
|
|
43730
|
-
const lowBits = new DataView(random.buffer, random.byteOffset, 4).getUint32(0, true) & 1073741823;
|
|
43731
|
-
return this.#messageIds.next(this.options.nowMilliseconds(), lowBits, modulo);
|
|
43732
|
-
}
|
|
43733
|
-
}
|
|
43734
42297
|
// node_modules/@inline-chat/realtime-sdk/dist/realtime/v3-connection.js
|
|
43735
|
-
var
|
|
42298
|
+
var BOOL_TRUE = 2574415285;
|
|
43736
42299
|
var CONNECT_TIMEOUT_MS = 30000;
|
|
43737
42300
|
var REQUEST_TIMEOUT_MS = 60000;
|
|
43738
42301
|
var SESSION_REVOKED_CLOSE_CODE = 4401;
|
|
@@ -44185,7 +42748,7 @@ class InlineProtocolV3Connection {
|
|
|
44185
42748
|
});
|
|
44186
42749
|
let result;
|
|
44187
42750
|
({ messageId, result } = await this.#sendPreparedContent(messageId, sequenceNumber, body));
|
|
44188
|
-
if (result.length !== 4 || new DataView(result.buffer, result.byteOffset, 4).getUint32(0, true) !==
|
|
42751
|
+
if (result.length !== 4 || new DataView(result.buffer, result.byteOffset, 4).getUint32(0, true) !== BOOL_TRUE) {
|
|
44189
42752
|
throw new InlineProtocolV3Error("protocol", "Server rejected temporary authorization-key binding");
|
|
44190
42753
|
}
|
|
44191
42754
|
}
|
|
@@ -47985,229 +46548,6 @@ class JsonFileStateStore {
|
|
|
47985
46548
|
await rename(tempPath, this.path);
|
|
47986
46549
|
}
|
|
47987
46550
|
}
|
|
47988
|
-
// node_modules/@inline-chat/realtime-sdk/dist/realtime/v3-client.js
|
|
47989
|
-
var cloneAuthorization3 = (value) => ({
|
|
47990
|
-
...value,
|
|
47991
|
-
key: value.key.slice(),
|
|
47992
|
-
keyId: value.keyId.slice()
|
|
47993
|
-
});
|
|
47994
|
-
var cloneCredentials2 = (value) => ({
|
|
47995
|
-
permanent: cloneAuthorization3(value.permanent),
|
|
47996
|
-
...value.temporary ? { temporary: cloneAuthorization3(value.temporary) } : {}
|
|
47997
|
-
});
|
|
47998
|
-
|
|
47999
|
-
class InlineRealtimeV3Client {
|
|
48000
|
-
#options;
|
|
48001
|
-
#login;
|
|
48002
|
-
#session;
|
|
48003
|
-
#credentials;
|
|
48004
|
-
#generation = 0;
|
|
48005
|
-
#activeSessionCalls = 0;
|
|
48006
|
-
#rotationDueSession;
|
|
48007
|
-
#rotationTask;
|
|
48008
|
-
#rotationError;
|
|
48009
|
-
constructor(options) {
|
|
48010
|
-
this.#options = options;
|
|
48011
|
-
}
|
|
48012
|
-
get credentials() {
|
|
48013
|
-
if (!this.#credentials)
|
|
48014
|
-
return;
|
|
48015
|
-
const credentials = cloneCredentials2(this.#credentials);
|
|
48016
|
-
if (this.#session)
|
|
48017
|
-
credentials.temporary = this.#session.authorization;
|
|
48018
|
-
if (this.#login)
|
|
48019
|
-
credentials.permanent = this.#login.authorization;
|
|
48020
|
-
return credentials;
|
|
48021
|
-
}
|
|
48022
|
-
get authenticated() {
|
|
48023
|
-
return this.#session !== undefined;
|
|
48024
|
-
}
|
|
48025
|
-
async beginLogin(request) {
|
|
48026
|
-
await this.close();
|
|
48027
|
-
this.#login = await InlineProtocolV3Connection.connect(this.#connectionOptions());
|
|
48028
|
-
this.#credentials = { permanent: this.#login.authorization };
|
|
48029
|
-
return await this.#login.authBegin(request);
|
|
48030
|
-
}
|
|
48031
|
-
async completeLogin(request) {
|
|
48032
|
-
const login = this.#login;
|
|
48033
|
-
if (!login || !this.#credentials)
|
|
48034
|
-
throw new InlineProtocolV3Error("unauthorized", "Native login has not started");
|
|
48035
|
-
const result = await login.authComplete(request);
|
|
48036
|
-
this.#credentials.permanent = login.authorization;
|
|
48037
|
-
if (result.state.oneofKind === "authorized")
|
|
48038
|
-
await this.#replaceAuthenticatedSession();
|
|
48039
|
-
return result;
|
|
48040
|
-
}
|
|
48041
|
-
async connect(credentials) {
|
|
48042
|
-
await this.close();
|
|
48043
|
-
const generation = this.#generation;
|
|
48044
|
-
this.#credentials = cloneCredentials2(credentials);
|
|
48045
|
-
const temporary = this.#credentials.temporary;
|
|
48046
|
-
if (temporary && temporary.expiresAt !== undefined) {
|
|
48047
|
-
const opened = await this.#openTemporarySession(generation, {
|
|
48048
|
-
authorization: temporary
|
|
48049
|
-
});
|
|
48050
|
-
const session2 = opened.session;
|
|
48051
|
-
try {
|
|
48052
|
-
await session2.probeTemporaryAuthorization();
|
|
48053
|
-
if (!session2.temporaryAuthorizationNeedsRotation()) {
|
|
48054
|
-
this.#requireCurrent(generation);
|
|
48055
|
-
this.#session = session2;
|
|
48056
|
-
if (opened.rotationDue)
|
|
48057
|
-
this.#handleRotationDue(session2, generation);
|
|
48058
|
-
return;
|
|
48059
|
-
}
|
|
48060
|
-
} catch (error) {
|
|
48061
|
-
if (!(error instanceof InlineProtocolV3Error) || error.code !== "unauthorized") {
|
|
48062
|
-
await session2.close();
|
|
48063
|
-
throw error;
|
|
48064
|
-
}
|
|
48065
|
-
}
|
|
48066
|
-
await session2.close();
|
|
48067
|
-
}
|
|
48068
|
-
await this.#replaceAuthenticatedSession(generation);
|
|
48069
|
-
}
|
|
48070
|
-
async reconnect() {
|
|
48071
|
-
const credentials = this.credentials;
|
|
48072
|
-
if (!credentials)
|
|
48073
|
-
throw new InlineProtocolV3Error("unauthorized", "No Inline Protocol credentials are available");
|
|
48074
|
-
await this.connect(credentials);
|
|
48075
|
-
}
|
|
48076
|
-
async callRpc(rpc) {
|
|
48077
|
-
return await this.#withSessionCall((session2) => session2.callRpc(rpc));
|
|
48078
|
-
}
|
|
48079
|
-
async createHttpUpload(request) {
|
|
48080
|
-
return await this.#withSessionCall((session2) => session2.createHttpUpload(request));
|
|
48081
|
-
}
|
|
48082
|
-
async finishHttpUpload(request) {
|
|
48083
|
-
return await this.#withSessionCall((session2) => session2.finishHttpUpload(request));
|
|
48084
|
-
}
|
|
48085
|
-
async close() {
|
|
48086
|
-
++this.#generation;
|
|
48087
|
-
const connections = [this.#login, this.#session].filter((value) => value !== undefined);
|
|
48088
|
-
const rotationTask = this.#rotationTask;
|
|
48089
|
-
this.#login = undefined;
|
|
48090
|
-
this.#session = undefined;
|
|
48091
|
-
this.#rotationDueSession = undefined;
|
|
48092
|
-
this.#rotationError = undefined;
|
|
48093
|
-
await Promise.allSettled([
|
|
48094
|
-
...connections.map((connection) => connection.close()),
|
|
48095
|
-
...rotationTask ? [rotationTask] : []
|
|
48096
|
-
]);
|
|
48097
|
-
}
|
|
48098
|
-
async#replaceAuthenticatedSession(generation = this.#generation, expectedSession) {
|
|
48099
|
-
const credentials = this.#credentials;
|
|
48100
|
-
if (!credentials)
|
|
48101
|
-
throw new InlineProtocolV3Error("unauthorized", "Permanent authorization key is unavailable");
|
|
48102
|
-
if (expectedSession && this.#session !== expectedSession)
|
|
48103
|
-
return;
|
|
48104
|
-
const previousSession = this.#session;
|
|
48105
|
-
this.#session = undefined;
|
|
48106
|
-
await previousSession?.close();
|
|
48107
|
-
this.#requireCurrent(generation);
|
|
48108
|
-
const opened = await this.#openTemporarySession(generation, {
|
|
48109
|
-
temporary: true
|
|
48110
|
-
});
|
|
48111
|
-
const session2 = opened.session;
|
|
48112
|
-
try {
|
|
48113
|
-
await session2.bindTemporary(credentials.permanent);
|
|
48114
|
-
this.#requireCurrent(generation);
|
|
48115
|
-
const nextCredentials = cloneCredentials2(credentials);
|
|
48116
|
-
nextCredentials.temporary = session2.authorization;
|
|
48117
|
-
await this.#options.onCredentials?.(cloneCredentials2(nextCredentials));
|
|
48118
|
-
this.#requireCurrent(generation);
|
|
48119
|
-
this.#credentials = nextCredentials;
|
|
48120
|
-
} catch (error) {
|
|
48121
|
-
await session2.close();
|
|
48122
|
-
throw error;
|
|
48123
|
-
}
|
|
48124
|
-
this.#session = session2;
|
|
48125
|
-
this.#rotationError = undefined;
|
|
48126
|
-
if (this.#rotationDueSession === expectedSession)
|
|
48127
|
-
this.#rotationDueSession = undefined;
|
|
48128
|
-
if (opened.rotationDue)
|
|
48129
|
-
this.#handleRotationDue(session2, generation);
|
|
48130
|
-
const login = this.#login;
|
|
48131
|
-
this.#login = undefined;
|
|
48132
|
-
await login?.close();
|
|
48133
|
-
}
|
|
48134
|
-
async#openTemporarySession(generation, authorization) {
|
|
48135
|
-
const owner = { rotationDue: false };
|
|
48136
|
-
const session2 = await InlineProtocolV3Connection.connect({
|
|
48137
|
-
...this.#connectionOptions(),
|
|
48138
|
-
...authorization,
|
|
48139
|
-
onRotationDue: () => {
|
|
48140
|
-
owner.rotationDue = true;
|
|
48141
|
-
if (owner.session)
|
|
48142
|
-
this.#handleRotationDue(owner.session, generation);
|
|
48143
|
-
}
|
|
48144
|
-
});
|
|
48145
|
-
owner.session = session2;
|
|
48146
|
-
return { session: session2, rotationDue: owner.rotationDue };
|
|
48147
|
-
}
|
|
48148
|
-
#handleRotationDue(session2, generation) {
|
|
48149
|
-
if (generation !== this.#generation || this.#session !== session2)
|
|
48150
|
-
return;
|
|
48151
|
-
this.#rotationDueSession = session2;
|
|
48152
|
-
this.#maybeRotate();
|
|
48153
|
-
}
|
|
48154
|
-
#maybeRotate() {
|
|
48155
|
-
const session2 = this.#rotationDueSession;
|
|
48156
|
-
if (!session2 || this.#session !== session2 || this.#activeSessionCalls > 0 || this.#rotationTask)
|
|
48157
|
-
return;
|
|
48158
|
-
const generation = this.#generation;
|
|
48159
|
-
const task = this.#replaceAuthenticatedSession(generation, session2);
|
|
48160
|
-
this.#rotationTask = task;
|
|
48161
|
-
task.catch((error) => {
|
|
48162
|
-
if (generation !== this.#generation)
|
|
48163
|
-
return;
|
|
48164
|
-
this.#rotationError = error instanceof Error ? error : new Error(String(error));
|
|
48165
|
-
}).finally(() => {
|
|
48166
|
-
if (this.#rotationTask === task)
|
|
48167
|
-
this.#rotationTask = undefined;
|
|
48168
|
-
if (generation === this.#generation)
|
|
48169
|
-
this.#maybeRotate();
|
|
48170
|
-
});
|
|
48171
|
-
}
|
|
48172
|
-
async#withSessionCall(operation) {
|
|
48173
|
-
if (this.#rotationTask)
|
|
48174
|
-
await this.#rotationTask;
|
|
48175
|
-
if (this.#rotationDueSession) {
|
|
48176
|
-
this.#maybeRotate();
|
|
48177
|
-
if (this.#rotationTask)
|
|
48178
|
-
await this.#rotationTask;
|
|
48179
|
-
}
|
|
48180
|
-
if (this.#rotationError)
|
|
48181
|
-
throw this.#rotationError;
|
|
48182
|
-
const session2 = this.#requireSession();
|
|
48183
|
-
this.#activeSessionCalls += 1;
|
|
48184
|
-
try {
|
|
48185
|
-
return await operation(session2);
|
|
48186
|
-
} finally {
|
|
48187
|
-
this.#activeSessionCalls -= 1;
|
|
48188
|
-
this.#maybeRotate();
|
|
48189
|
-
}
|
|
48190
|
-
}
|
|
48191
|
-
#requireCurrent(generation) {
|
|
48192
|
-
if (generation !== this.#generation) {
|
|
48193
|
-
throw new InlineProtocolV3Error("closed", "Inline Protocol client lifecycle changed");
|
|
48194
|
-
}
|
|
48195
|
-
}
|
|
48196
|
-
#requireSession() {
|
|
48197
|
-
if (!this.#session)
|
|
48198
|
-
throw new InlineProtocolV3Error("unauthorized", "Inline Protocol authenticated session is not connected");
|
|
48199
|
-
return this.#session;
|
|
48200
|
-
}
|
|
48201
|
-
#connectionOptions() {
|
|
48202
|
-
return {
|
|
48203
|
-
url: this.#options.url,
|
|
48204
|
-
rsaPublicKeys: this.#options.rsaPublicKeys,
|
|
48205
|
-
connectTimeoutMs: this.#options.connectTimeoutMs,
|
|
48206
|
-
requestTimeoutMs: this.#options.requestTimeoutMs,
|
|
48207
|
-
onUpdate: this.#options.onUpdate
|
|
48208
|
-
};
|
|
48209
|
-
}
|
|
48210
|
-
}
|
|
48211
46551
|
// node_modules/@inline-chat/protocol/dist/vectors.js
|
|
48212
46552
|
var portableCoreV1Vector = {
|
|
48213
46553
|
authKeyHex: Array.from({ length: 256 }, (_, index) => index.toString(16).padStart(2, "0")).join(""),
|
|
@@ -48507,7 +46847,7 @@ function buildHermesTelemetryEvent(operation, error, options = {}) {
|
|
|
48507
46847
|
async function resolveRelease() {
|
|
48508
46848
|
releasePromise ??= (async () => {
|
|
48509
46849
|
for (const candidate of [
|
|
48510
|
-
new URL("
|
|
46850
|
+
new URL("../../../../package.json", import.meta.url),
|
|
48511
46851
|
new URL("../../package.json", import.meta.url)
|
|
48512
46852
|
]) {
|
|
48513
46853
|
try {
|
|
@@ -49960,7 +48300,7 @@ function sleep(ms) {
|
|
|
49960
48300
|
}
|
|
49961
48301
|
async function packageVersion() {
|
|
49962
48302
|
const candidates = [
|
|
49963
|
-
new URL("
|
|
48303
|
+
new URL("../../../../package.json", import.meta.url),
|
|
49964
48304
|
new URL("../../package.json", import.meta.url)
|
|
49965
48305
|
];
|
|
49966
48306
|
for (const pkgUrl of candidates) {
|