@mtkruto/node 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +165 -0
- package/README.md +1 -0
- package/esm/_dnt.shims.js +68 -0
- package/esm/client/client.js +169 -0
- package/esm/client/client_abstract.js +51 -0
- package/esm/client/client_plain.js +112 -0
- package/esm/connection/connection.js +2 -0
- package/esm/connection/connection_web_socket.js +90 -0
- package/esm/constants.js +60 -0
- package/esm/deps/deno.land/std@0.186.0/fmt/colors.js +474 -0
- package/esm/deps/deno.land/std@0.186.0/testing/_diff.js +311 -0
- package/esm/deps/deno.land/std@0.186.0/testing/_format.js +23 -0
- package/esm/deps/deno.land/std@0.186.0/testing/asserts.js +633 -0
- package/esm/deps/deno.land/x/crc32@v0.2.0/mod.js +105 -0
- package/esm/deps/deno.land/x/tgcrypto@0.1.1/mod.js +68 -0
- package/esm/deps/deno.land/x/tgcrypto@0.1.1/tgcrypto.js +1127 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/gzip/gzip.js +239 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/utils/uint8.js +10 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/deflate.js +139 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/inflate.js +176 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/mod.js +2 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/adler32.js +19 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/crc32.js +25 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/deflate.js +1941 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/gzheader.js +85 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inffast.js +321 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inflate.js +1658 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inftrees.js +355 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/messages.js +11 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/status.js +42 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/trees.js +1107 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/zstream.js +86 -0
- package/esm/deps.js +4 -0
- package/esm/mod.js +4 -0
- package/esm/package.json +3 -0
- package/esm/tl/0_tl_raw_reader.js +62 -0
- package/esm/tl/0_tl_raw_writer.js +60 -0
- package/esm/tl/1_tl_object.js +149 -0
- package/esm/tl/2_types.js +48220 -0
- package/esm/tl/3_functions.js +19856 -0
- package/esm/tl/3_tl_object_deserializer.js +72 -0
- package/esm/tl/3_tl_reader.js +16 -0
- package/esm/tl/3_tl_writer.js +7 -0
- package/esm/tl/4_rpc_result.js +27 -0
- package/esm/tl/5_message.js +54 -0
- package/esm/tl/6_message_container.js +35 -0
- package/esm/transport/transport.js +32 -0
- package/esm/transport/transport_intermediate.js +56 -0
- package/esm/transport/transport_provider.js +23 -0
- package/esm/types.js +1 -0
- package/esm/utilities/0_bigint.js +37 -0
- package/esm/utilities/0_buffer.js +33 -0
- package/esm/utilities/0_crypto.js +35 -0
- package/esm/utilities/0_hash.js +7 -0
- package/esm/utilities/1_auth.js +29 -0
- package/esm/utilities/1_message.js +94 -0
- package/esm/utilities/1_obfuscation.js +33 -0
- package/package.json +40 -0
- package/script/_dnt.shims.js +77 -0
- package/script/client/client.js +173 -0
- package/script/client/client_abstract.js +55 -0
- package/script/client/client_plain.js +116 -0
- package/script/connection/connection.js +6 -0
- package/script/connection/connection_web_socket.js +117 -0
- package/script/constants.js +63 -0
- package/script/deps/deno.land/std@0.186.0/fmt/colors.js +548 -0
- package/script/deps/deno.land/std@0.186.0/testing/_diff.js +317 -0
- package/script/deps/deno.land/std@0.186.0/testing/_format.js +50 -0
- package/script/deps/deno.land/std@0.186.0/testing/asserts.js +659 -0
- package/script/deps/deno.land/x/crc32@v0.2.0/mod.js +113 -0
- package/script/deps/deno.land/x/tgcrypto@0.1.1/mod.js +82 -0
- package/script/deps/deno.land/x/tgcrypto@0.1.1/tgcrypto.js +1152 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/gzip/gzip.js +271 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/utils/uint8.js +14 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/deflate.js +172 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/inflate.js +208 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/mod.js +18 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/adler32.js +22 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/crc32.js +30 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/deflate.js +1976 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/gzheader.js +88 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inffast.js +324 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inflate.js +1674 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inftrees.js +358 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/messages.js +14 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/status.js +44 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/trees.js +1115 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/zstream.js +89 -0
- package/script/deps.js +30 -0
- package/script/mod.js +32 -0
- package/script/package.json +3 -0
- package/script/tl/0_tl_raw_reader.js +66 -0
- package/script/tl/0_tl_raw_writer.js +64 -0
- package/script/tl/1_tl_object.js +156 -0
- package/script/tl/2_types.js +49824 -0
- package/script/tl/3_functions.js +20413 -0
- package/script/tl/3_tl_object_deserializer.js +76 -0
- package/script/tl/3_tl_reader.js +20 -0
- package/script/tl/3_tl_writer.js +11 -0
- package/script/tl/4_rpc_result.js +31 -0
- package/script/tl/5_message.js +58 -0
- package/script/tl/6_message_container.js +39 -0
- package/script/transport/transport.js +36 -0
- package/script/transport/transport_intermediate.js +60 -0
- package/script/transport/transport_provider.js +27 -0
- package/script/types.js +2 -0
- package/script/utilities/0_bigint.js +67 -0
- package/script/utilities/0_buffer.js +38 -0
- package/script/utilities/0_crypto.js +39 -0
- package/script/utilities/0_hash.js +35 -0
- package/script/utilities/1_auth.js +56 -0
- package/script/utilities/1_message.js +102 -0
- package/script/utilities/1_obfuscation.js +60 -0
- package/types/_dnt.shims.d.ts +10 -0
- package/types/client/client.d.ts +19 -0
- package/types/client/client_abstract.d.ts +20 -0
- package/types/client/client_plain.d.ts +10 -0
- package/types/connection/connection.d.ts +7 -0
- package/types/connection/connection_web_socket.d.ts +13 -0
- package/types/constants.d.ts +2 -0
- package/types/deps/deno.land/std@0.186.0/fmt/colors.d.ts +270 -0
- package/types/deps/deno.land/std@0.186.0/testing/_diff.d.ts +26 -0
- package/types/deps/deno.land/std@0.186.0/testing/_format.d.ts +1 -0
- package/types/deps/deno.land/std@0.186.0/testing/asserts.d.ts +284 -0
- package/types/deps/deno.land/x/crc32@v0.2.0/mod.d.ts +15 -0
- package/types/deps/deno.land/x/tgcrypto@0.1.1/mod.d.ts +47 -0
- package/types/deps/deno.land/x/tgcrypto@0.1.1/tgcrypto.d.ts +2 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/gzip/gzip.d.ts +16 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/utils/uint8.d.ts +1 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/deflate.d.ts +29 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/inflate.d.ts +23 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/mod.d.ts +2 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/adler32.d.ts +1 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/crc32.d.ts +2 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/deflate.d.ts +78 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/gzheader.d.ts +12 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inffast.d.ts +1 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inflate.d.ts +47 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inftrees.d.ts +1 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/messages.d.ts +12 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/status.d.ts +30 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/trees.d.ts +5 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/zstream.d.ts +14 -0
- package/types/deps.d.ts +4 -0
- package/types/mod.d.ts +4 -0
- package/types/tl/0_tl_raw_reader.d.ts +13 -0
- package/types/tl/0_tl_raw_writer.d.ts +13 -0
- package/types/tl/1_tl_object.d.ts +36 -0
- package/types/tl/2_types.d.ts +14815 -0
- package/types/tl/3_functions.d.ts +6122 -0
- package/types/tl/3_tl_object_deserializer.d.ts +3 -0
- package/types/tl/3_tl_reader.d.ts +4 -0
- package/types/tl/3_tl_writer.d.ts +5 -0
- package/types/tl/4_rpc_result.d.ts +8 -0
- package/types/tl/5_message.d.ts +11 -0
- package/types/tl/6_message_container.d.ts +9 -0
- package/types/transport/transport.d.ts +15 -0
- package/types/transport/transport_intermediate.d.ts +11 -0
- package/types/transport/transport_provider.d.ts +12 -0
- package/types/types.d.ts +1 -0
- package/types/utilities/0_bigint.d.ts +4 -0
- package/types/utilities/0_buffer.d.ts +2 -0
- package/types/utilities/0_crypto.d.ts +8 -0
- package/types/utilities/0_hash.d.ts +2 -0
- package/types/utilities/1_auth.d.ts +1 -0
- package/types/utilities/1_message.d.ts +10 -0
- package/types/utilities/1_obfuscation.d.ts +6 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
export default class ZStream {
|
|
2
|
+
constructor() {
|
|
3
|
+
/* next input byte */
|
|
4
|
+
Object.defineProperty(this, "input", {
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true,
|
|
8
|
+
value: null
|
|
9
|
+
}); // JS specific, because we have no pointers
|
|
10
|
+
Object.defineProperty(this, "next_in", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true,
|
|
14
|
+
value: 0
|
|
15
|
+
});
|
|
16
|
+
/* number of bytes available at input */
|
|
17
|
+
Object.defineProperty(this, "avail_in", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: 0
|
|
22
|
+
});
|
|
23
|
+
/* total number of input bytes read so far */
|
|
24
|
+
Object.defineProperty(this, "total_in", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
configurable: true,
|
|
27
|
+
writable: true,
|
|
28
|
+
value: 0
|
|
29
|
+
});
|
|
30
|
+
/* next output byte should be put there */
|
|
31
|
+
Object.defineProperty(this, "output", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
configurable: true,
|
|
34
|
+
writable: true,
|
|
35
|
+
value: null
|
|
36
|
+
}); // JS specific, because we have no pointers
|
|
37
|
+
Object.defineProperty(this, "next_out", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
configurable: true,
|
|
40
|
+
writable: true,
|
|
41
|
+
value: 0
|
|
42
|
+
});
|
|
43
|
+
/* remaining free space at output */
|
|
44
|
+
Object.defineProperty(this, "avail_out", {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
configurable: true,
|
|
47
|
+
writable: true,
|
|
48
|
+
value: 0
|
|
49
|
+
});
|
|
50
|
+
/* total number of bytes output so far */
|
|
51
|
+
Object.defineProperty(this, "total_out", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
configurable: true,
|
|
54
|
+
writable: true,
|
|
55
|
+
value: 0
|
|
56
|
+
});
|
|
57
|
+
/* last error message, NULL if no error */
|
|
58
|
+
Object.defineProperty(this, "msg", {
|
|
59
|
+
enumerable: true,
|
|
60
|
+
configurable: true,
|
|
61
|
+
writable: true,
|
|
62
|
+
value: "" /*Z_NULL*/
|
|
63
|
+
});
|
|
64
|
+
/* not visible by applications */
|
|
65
|
+
Object.defineProperty(this, "state", {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
configurable: true,
|
|
68
|
+
writable: true,
|
|
69
|
+
value: null
|
|
70
|
+
});
|
|
71
|
+
/* best guess about the data type: binary or text */
|
|
72
|
+
Object.defineProperty(this, "data_type", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
configurable: true,
|
|
75
|
+
writable: true,
|
|
76
|
+
value: 2 /*Z_UNKNOWN*/
|
|
77
|
+
});
|
|
78
|
+
/* adler32 value of the uncompressed data */
|
|
79
|
+
Object.defineProperty(this, "adler", {
|
|
80
|
+
enumerable: true,
|
|
81
|
+
configurable: true,
|
|
82
|
+
writable: true,
|
|
83
|
+
value: 0
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
package/esm/deps.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export * from "./deps/deno.land/std@0.186.0/testing/asserts.js";
|
|
2
|
+
export { ctr256Decrypt, ctr256Encrypt, factorize, ige256Decrypt, ige256Encrypt, init as initTgCrypto } from "./deps/deno.land/x/tgcrypto@0.1.1/mod.js";
|
|
3
|
+
export { gunzip, gzip } from "./deps/raw.githubusercontent.com/MTKruto/compress/master/gzip/gzip.js";
|
|
4
|
+
export { Mutex } from "async-mutex";
|
package/esm/mod.js
ADDED
package/esm/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { bigIntFromBuffer } from "../utilities/0_bigint.js";
|
|
2
|
+
export class TLRawReader {
|
|
3
|
+
constructor(_buffer) {
|
|
4
|
+
Object.defineProperty(this, "_buffer", {
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true,
|
|
8
|
+
value: _buffer
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
get buffer() {
|
|
12
|
+
return this._buffer;
|
|
13
|
+
}
|
|
14
|
+
read(count) {
|
|
15
|
+
if (this._buffer.length < count) {
|
|
16
|
+
throw new Error("No data remaining");
|
|
17
|
+
}
|
|
18
|
+
const buffer = this._buffer.slice(0, count);
|
|
19
|
+
this._buffer = this._buffer.slice(count);
|
|
20
|
+
return buffer;
|
|
21
|
+
}
|
|
22
|
+
readInt24(signed = true) {
|
|
23
|
+
const buffer = this.read(24 / 8);
|
|
24
|
+
return Number(bigIntFromBuffer(buffer, true, signed));
|
|
25
|
+
}
|
|
26
|
+
readInt32(signed = true) {
|
|
27
|
+
const buffer = this.read(32 / 8);
|
|
28
|
+
return Number(bigIntFromBuffer(buffer, true, signed));
|
|
29
|
+
}
|
|
30
|
+
readInt64(signed = true) {
|
|
31
|
+
const buffer = this.read(64 / 8);
|
|
32
|
+
return bigIntFromBuffer(buffer, true, signed);
|
|
33
|
+
}
|
|
34
|
+
readInt128(signed = true) {
|
|
35
|
+
const buffer = this.read(128 / 8);
|
|
36
|
+
return bigIntFromBuffer(buffer, true, signed);
|
|
37
|
+
}
|
|
38
|
+
readInt256(signed = true) {
|
|
39
|
+
const buffer = this.read(256 / 8);
|
|
40
|
+
return bigIntFromBuffer(buffer, true, signed);
|
|
41
|
+
}
|
|
42
|
+
readBytes() {
|
|
43
|
+
let L = this.read(1)[0];
|
|
44
|
+
let padding;
|
|
45
|
+
if (L > 253) {
|
|
46
|
+
L = this.readInt24();
|
|
47
|
+
padding = L % 4;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
padding = (L + 1) % 4;
|
|
51
|
+
}
|
|
52
|
+
const bytes = this.read(L);
|
|
53
|
+
if (padding > 0) {
|
|
54
|
+
padding = 4 - padding;
|
|
55
|
+
this.read(padding);
|
|
56
|
+
}
|
|
57
|
+
return bytes;
|
|
58
|
+
}
|
|
59
|
+
readString() {
|
|
60
|
+
return new TextDecoder().decode(this.readBytes());
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { bufferFromBigInt, concat } from "../utilities/0_buffer.js";
|
|
2
|
+
export class TLRawWriter {
|
|
3
|
+
constructor() {
|
|
4
|
+
Object.defineProperty(this, "_buffer", {
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true,
|
|
8
|
+
value: new Uint8Array()
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
get buffer() {
|
|
12
|
+
return this._buffer;
|
|
13
|
+
}
|
|
14
|
+
write(buffer) {
|
|
15
|
+
this._buffer = concat(this._buffer, buffer);
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
writeInt24(int, signed = true) {
|
|
19
|
+
this.write(bufferFromBigInt(int, 24 / 7, true, signed));
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
writeInt32(int, signed = true) {
|
|
23
|
+
this.write(bufferFromBigInt(int, 32 / 8, true, signed));
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
writeInt64(int, signed = true) {
|
|
27
|
+
this.write(bufferFromBigInt(int, 64 / 8, true, signed));
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
writeInt128(int, signed = true) {
|
|
31
|
+
this.write(bufferFromBigInt(int, 128 / 8, true, signed));
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
writeInt256(int, signed = true) {
|
|
35
|
+
this.write(bufferFromBigInt(int, 256 / 8, true, signed));
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
writeBytes(bytes) {
|
|
39
|
+
let padding;
|
|
40
|
+
if (bytes.length > 253) {
|
|
41
|
+
this.write(new Uint8Array([254]));
|
|
42
|
+
this.writeInt24(bytes.length);
|
|
43
|
+
padding = bytes.length % 4;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
this.write(new Uint8Array([bytes.length]));
|
|
47
|
+
padding = (bytes.length + 1) % 4;
|
|
48
|
+
}
|
|
49
|
+
this.write(bytes);
|
|
50
|
+
if (padding > 0) {
|
|
51
|
+
padding = 4 - padding;
|
|
52
|
+
this.write(new Uint8Array(padding));
|
|
53
|
+
}
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
writeString(string) {
|
|
57
|
+
this.writeBytes(new TextEncoder().encode(string));
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { assertEquals, assertFalse } from "../deps.js";
|
|
2
|
+
import { TLRawWriter } from "./0_tl_raw_writer.js";
|
|
3
|
+
export const flags = Symbol("flags");
|
|
4
|
+
export const id = Symbol("id");
|
|
5
|
+
export const params = Symbol("params");
|
|
6
|
+
export const paramDesc = Symbol("paramDesc");
|
|
7
|
+
export const length = Symbol("length");
|
|
8
|
+
export function isOptionalParam(ntype) {
|
|
9
|
+
return ntype.includes("?");
|
|
10
|
+
}
|
|
11
|
+
export function analyzeOptionalParam(ntype) {
|
|
12
|
+
if (!isOptionalParam(ntype)) {
|
|
13
|
+
throw new Error("Parameter not optional");
|
|
14
|
+
}
|
|
15
|
+
const flagField = ntype.split(".")[0];
|
|
16
|
+
assertEquals(typeof flagField, "string");
|
|
17
|
+
const bitIndex = Number(ntype.split("?")[0].split(".")[1]);
|
|
18
|
+
assertFalse(isNaN(bitIndex));
|
|
19
|
+
return { flagField, bitIndex };
|
|
20
|
+
}
|
|
21
|
+
function serializeSingleParam(writer, value, type, ntype) {
|
|
22
|
+
if (isTLObjectConstructor(type)) {
|
|
23
|
+
if ((type.name == "TypeX" && value instanceof TLObject) ||
|
|
24
|
+
value instanceof type) {
|
|
25
|
+
writer.write(value.serialize());
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
throw new Error("a");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (type == Uint8Array) {
|
|
33
|
+
if ((value instanceof Uint8Array)) {
|
|
34
|
+
writer.writeBytes(value);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
throw new Error("Expected Uint8Array");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
switch (type) {
|
|
41
|
+
case "bigint":
|
|
42
|
+
if (typeof value === "bigint") {
|
|
43
|
+
if (ntype == "int128") {
|
|
44
|
+
writer.writeInt128(value);
|
|
45
|
+
}
|
|
46
|
+
else if (ntype === "int256") {
|
|
47
|
+
writer.writeInt256(value);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
writer.writeInt64(value);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
throw new Error("Expected bigint");
|
|
55
|
+
}
|
|
56
|
+
break;
|
|
57
|
+
case "boolean":
|
|
58
|
+
if (typeof value === "boolean") {
|
|
59
|
+
if (value) {
|
|
60
|
+
writer.writeInt32(0x997275B5);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
writer.writeInt32(0xBC799737);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
throw new Error("Expected boolean");
|
|
68
|
+
}
|
|
69
|
+
break;
|
|
70
|
+
case "number":
|
|
71
|
+
if (typeof value === "number") {
|
|
72
|
+
writer.writeInt32(value);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
throw new Error("Expected number");
|
|
76
|
+
}
|
|
77
|
+
break;
|
|
78
|
+
case "string":
|
|
79
|
+
if (typeof value === "string") {
|
|
80
|
+
writer.writeString(value);
|
|
81
|
+
}
|
|
82
|
+
else if (value instanceof Uint8Array) {
|
|
83
|
+
writer.writeBytes(value);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
throw new Error("Expected string or Uint8Array");
|
|
87
|
+
}
|
|
88
|
+
break;
|
|
89
|
+
case "true":
|
|
90
|
+
if (value === true) {
|
|
91
|
+
writer.writeInt32(0x997275B5);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
throw new Error("Expected true");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
export class TLObject {
|
|
99
|
+
static get [paramDesc]() {
|
|
100
|
+
// unimpl
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
get [length]() {
|
|
104
|
+
return this.serialize().byteLength;
|
|
105
|
+
}
|
|
106
|
+
serialize() {
|
|
107
|
+
const writer = new TLRawWriter();
|
|
108
|
+
writer.writeInt32(this[id], false);
|
|
109
|
+
for (const [value, type, ntype] of this[params]) {
|
|
110
|
+
if (isOptionalParam(ntype) && value == null) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (type == flags) {
|
|
114
|
+
let flags = 0;
|
|
115
|
+
const flagField_ = value;
|
|
116
|
+
for (const [value, _, ntype] of this[params]) {
|
|
117
|
+
if (isOptionalParam(ntype)) {
|
|
118
|
+
const { flagField, bitIndex } = analyzeOptionalParam(ntype);
|
|
119
|
+
if (flagField == flagField_) {
|
|
120
|
+
if (value != null) {
|
|
121
|
+
flags |= 1 << bitIndex;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
writer.writeInt32(flags);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (type instanceof Array) {
|
|
130
|
+
const itemsType = type[0];
|
|
131
|
+
if (!Array.isArray(value)) {
|
|
132
|
+
throw new Error("Expected array");
|
|
133
|
+
}
|
|
134
|
+
writer.writeInt32(0x1CB5C415); // vector constructor
|
|
135
|
+
writer.writeInt32(value.length);
|
|
136
|
+
for (const item of value) {
|
|
137
|
+
serializeSingleParam(writer, item, itemsType, ntype);
|
|
138
|
+
}
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
serializeSingleParam(writer, value, type, ntype);
|
|
142
|
+
}
|
|
143
|
+
return writer.buffer;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
export function isTLObjectConstructor(t) {
|
|
147
|
+
// deno-lint-ignore no-explicit-any
|
|
148
|
+
return t[paramDesc] instanceof Array;
|
|
149
|
+
}
|