@mtcute/core 0.1.0
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 +8 -0
- package/README.md +26 -0
- package/cjs/base-client.d.ts +297 -0
- package/cjs/base-client.js +324 -0
- package/cjs/base-client.js.map +1 -0
- package/cjs/index.d.ts +10 -0
- package/cjs/index.js +30 -0
- package/cjs/index.js.map +1 -0
- package/cjs/network/auth-key.d.ts +21 -0
- package/cjs/network/auth-key.js +101 -0
- package/cjs/network/auth-key.js.map +1 -0
- package/cjs/network/authorization.d.ts +9 -0
- package/cjs/network/authorization.js +332 -0
- package/cjs/network/authorization.js.map +1 -0
- package/cjs/network/config-manager.d.ts +33 -0
- package/cjs/network/config-manager.js +93 -0
- package/cjs/network/config-manager.js.map +1 -0
- package/cjs/network/index.d.ts +4 -0
- package/cjs/network/index.js +20 -0
- package/cjs/network/index.js.map +1 -0
- package/cjs/network/mtproto-session.d.ts +116 -0
- package/cjs/network/mtproto-session.js +209 -0
- package/cjs/network/mtproto-session.js.map +1 -0
- package/cjs/network/multi-session-connection.d.ts +33 -0
- package/cjs/network/multi-session-connection.js +243 -0
- package/cjs/network/multi-session-connection.js.map +1 -0
- package/cjs/network/network-manager.d.ts +190 -0
- package/cjs/network/network-manager.js +547 -0
- package/cjs/network/network-manager.js.map +1 -0
- package/cjs/network/persistent-connection.d.ts +51 -0
- package/cjs/network/persistent-connection.js +173 -0
- package/cjs/network/persistent-connection.js.map +1 -0
- package/cjs/network/reconnection.d.ts +11 -0
- package/cjs/network/reconnection.js +18 -0
- package/cjs/network/reconnection.js.map +1 -0
- package/cjs/network/session-connection.d.ts +72 -0
- package/cjs/network/session-connection.js +1363 -0
- package/cjs/network/session-connection.js.map +1 -0
- package/cjs/network/transports/abstract.d.ts +99 -0
- package/cjs/network/transports/abstract.js +38 -0
- package/cjs/network/transports/abstract.js.map +1 -0
- package/cjs/network/transports/index.d.ts +8 -0
- package/cjs/network/transports/index.js +26 -0
- package/cjs/network/transports/index.js.map +1 -0
- package/cjs/network/transports/intermediate.d.ts +20 -0
- package/cjs/network/transports/intermediate.js +67 -0
- package/cjs/network/transports/intermediate.js.map +1 -0
- package/cjs/network/transports/obfuscated.d.ts +18 -0
- package/cjs/network/transports/obfuscated.js +83 -0
- package/cjs/network/transports/obfuscated.js.map +1 -0
- package/cjs/network/transports/streamed.d.ts +24 -0
- package/cjs/network/transports/streamed.js +32 -0
- package/cjs/network/transports/streamed.js.map +1 -0
- package/cjs/network/transports/tcp.d.ts +33 -0
- package/cjs/network/transports/tcp.js +130 -0
- package/cjs/network/transports/tcp.js.map +1 -0
- package/cjs/network/transports/websocket.d.ts +47 -0
- package/cjs/network/transports/websocket.js +124 -0
- package/cjs/network/transports/websocket.js.map +1 -0
- package/cjs/network/transports/wrapped.d.ts +11 -0
- package/cjs/network/transports/wrapped.js +26 -0
- package/cjs/network/transports/wrapped.js.map +1 -0
- package/cjs/package.json +3 -0
- package/cjs/storage/abstract.d.ts +174 -0
- package/cjs/storage/abstract.js +3 -0
- package/cjs/storage/abstract.js.map +1 -0
- package/cjs/storage/index.d.ts +5 -0
- package/cjs/storage/index.js +22 -0
- package/cjs/storage/index.js.map +1 -0
- package/cjs/storage/json-file.d.ts +31 -0
- package/cjs/storage/json-file.js +90 -0
- package/cjs/storage/json-file.js.map +1 -0
- package/cjs/storage/json.d.ts +9 -0
- package/cjs/storage/json.js +65 -0
- package/cjs/storage/json.js.map +1 -0
- package/cjs/storage/localstorage.d.ts +7 -0
- package/cjs/storage/localstorage.js +25 -0
- package/cjs/storage/localstorage.js.map +1 -0
- package/cjs/storage/memory.d.ts +98 -0
- package/cjs/storage/memory.js +299 -0
- package/cjs/storage/memory.js.map +1 -0
- package/cjs/types/errors.d.ts +53 -0
- package/cjs/types/errors.js +58 -0
- package/cjs/types/errors.js.map +1 -0
- package/cjs/types/index.d.ts +3 -0
- package/cjs/types/index.js +20 -0
- package/cjs/types/index.js.map +1 -0
- package/cjs/types/peers.d.ts +4 -0
- package/cjs/types/peers.js +3 -0
- package/cjs/types/peers.js.map +1 -0
- package/cjs/types/utils.d.ts +6 -0
- package/cjs/types/utils.js +9 -0
- package/cjs/types/utils.js.map +1 -0
- package/cjs/utils/async-lock.d.ts +10 -0
- package/cjs/utils/async-lock.js +43 -0
- package/cjs/utils/async-lock.js.map +1 -0
- package/cjs/utils/bigint-utils.d.ts +40 -0
- package/cjs/utils/bigint-utils.js +104 -0
- package/cjs/utils/bigint-utils.js.map +1 -0
- package/cjs/utils/binary/asn1-parser.d.ts +17 -0
- package/cjs/utils/binary/asn1-parser.js +121 -0
- package/cjs/utils/binary/asn1-parser.js.map +1 -0
- package/cjs/utils/buffer-utils.d.ts +21 -0
- package/cjs/utils/buffer-utils.js +63 -0
- package/cjs/utils/buffer-utils.js.map +1 -0
- package/cjs/utils/condition-variable.d.ts +9 -0
- package/cjs/utils/condition-variable.js +28 -0
- package/cjs/utils/condition-variable.js.map +1 -0
- package/cjs/utils/controllable-promise.d.ts +16 -0
- package/cjs/utils/controllable-promise.js +25 -0
- package/cjs/utils/controllable-promise.js.map +1 -0
- package/cjs/utils/crypto/abstract.d.ts +23 -0
- package/cjs/utils/crypto/abstract.js +19 -0
- package/cjs/utils/crypto/abstract.js.map +1 -0
- package/cjs/utils/crypto/common.d.ts +12 -0
- package/cjs/utils/crypto/common.js +54 -0
- package/cjs/utils/crypto/common.js.map +1 -0
- package/cjs/utils/crypto/factorization.d.ts +5 -0
- package/cjs/utils/crypto/factorization.js +69 -0
- package/cjs/utils/crypto/factorization.js.map +1 -0
- package/cjs/utils/crypto/index.d.ts +5 -0
- package/cjs/utils/crypto/index.js +23 -0
- package/cjs/utils/crypto/index.js.map +1 -0
- package/cjs/utils/crypto/keys.d.ts +27 -0
- package/cjs/utils/crypto/keys.js +70 -0
- package/cjs/utils/crypto/keys.js.map +1 -0
- package/cjs/utils/crypto/miller-rabin.d.ts +2 -0
- package/cjs/utils/crypto/miller-rabin.js +44 -0
- package/cjs/utils/crypto/miller-rabin.js.map +1 -0
- package/cjs/utils/crypto/mtproto.d.ts +31 -0
- package/cjs/utils/crypto/mtproto.js +66 -0
- package/cjs/utils/crypto/mtproto.js.map +1 -0
- package/cjs/utils/crypto/node-crypto.d.ts +10 -0
- package/cjs/utils/crypto/node-crypto.js +46 -0
- package/cjs/utils/crypto/node-crypto.js.map +1 -0
- package/cjs/utils/crypto/password.d.ts +29 -0
- package/cjs/utils/crypto/password.js +106 -0
- package/cjs/utils/crypto/password.js.map +1 -0
- package/cjs/utils/crypto/subtle.d.ts +12 -0
- package/cjs/utils/crypto/subtle.js +86 -0
- package/cjs/utils/crypto/subtle.js.map +1 -0
- package/cjs/utils/crypto/utils.d.ts +14 -0
- package/cjs/utils/crypto/utils.js +30 -0
- package/cjs/utils/crypto/utils.js.map +1 -0
- package/cjs/utils/default-dcs.d.ts +7 -0
- package/cjs/utils/default-dcs.js +76 -0
- package/cjs/utils/default-dcs.js.map +1 -0
- package/cjs/utils/deque.d.ts +29 -0
- package/cjs/utils/deque.js +210 -0
- package/cjs/utils/deque.js.map +1 -0
- package/cjs/utils/early-timer.d.ts +42 -0
- package/cjs/utils/early-timer.js +79 -0
- package/cjs/utils/early-timer.js.map +1 -0
- package/cjs/utils/flood-control.d.ts +14 -0
- package/cjs/utils/flood-control.js +65 -0
- package/cjs/utils/flood-control.js.map +1 -0
- package/cjs/utils/function-utils.d.ts +13 -0
- package/cjs/utils/function-utils.js +30 -0
- package/cjs/utils/function-utils.js.map +1 -0
- package/cjs/utils/index.d.ts +24 -0
- package/cjs/utils/index.js +41 -0
- package/cjs/utils/index.js.map +1 -0
- package/cjs/utils/linked-list.d.ts +21 -0
- package/cjs/utils/linked-list.js +73 -0
- package/cjs/utils/linked-list.js.map +1 -0
- package/cjs/utils/links/bots.d.ts +71 -0
- package/cjs/utils/links/bots.js +259 -0
- package/cjs/utils/links/bots.js.map +1 -0
- package/cjs/utils/links/bundle.d.ts +7 -0
- package/cjs/utils/links/bundle.js +24 -0
- package/cjs/utils/links/bundle.js.map +1 -0
- package/cjs/utils/links/calls.d.ts +16 -0
- package/cjs/utils/links/calls.js +59 -0
- package/cjs/utils/links/calls.js.map +1 -0
- package/cjs/utils/links/chat.d.ts +46 -0
- package/cjs/utils/links/chat.js +160 -0
- package/cjs/utils/links/chat.js.map +1 -0
- package/cjs/utils/links/common.d.ts +31 -0
- package/cjs/utils/links/common.js +60 -0
- package/cjs/utils/links/common.js.map +1 -0
- package/cjs/utils/links/index.d.ts +2 -0
- package/cjs/utils/links/index.js +29 -0
- package/cjs/utils/links/index.js.map +1 -0
- package/cjs/utils/links/misc.d.ts +19 -0
- package/cjs/utils/links/misc.js +77 -0
- package/cjs/utils/links/misc.js.map +1 -0
- package/cjs/utils/links/proxy.d.ts +17 -0
- package/cjs/utils/links/proxy.js +61 -0
- package/cjs/utils/links/proxy.js.map +1 -0
- package/cjs/utils/links/stickers.d.ts +9 -0
- package/cjs/utils/links/stickers.js +28 -0
- package/cjs/utils/links/stickers.js.map +1 -0
- package/cjs/utils/links/user.d.ts +27 -0
- package/cjs/utils/links/user.js +81 -0
- package/cjs/utils/links/user.js.map +1 -0
- package/cjs/utils/logger.d.ts +54 -0
- package/cjs/utils/logger.js +158 -0
- package/cjs/utils/logger.js.map +1 -0
- package/cjs/utils/long-utils.d.ts +75 -0
- package/cjs/utils/long-utils.js +161 -0
- package/cjs/utils/long-utils.js.map +1 -0
- package/cjs/utils/lru-map.d.ts +21 -0
- package/cjs/utils/lru-map.js +107 -0
- package/cjs/utils/lru-map.js.map +1 -0
- package/cjs/utils/lru-set.d.ts +22 -0
- package/cjs/utils/lru-set.js +48 -0
- package/cjs/utils/lru-set.js.map +1 -0
- package/cjs/utils/misc-utils.d.ts +7 -0
- package/cjs/utils/misc-utils.js +15 -0
- package/cjs/utils/misc-utils.js.map +1 -0
- package/cjs/utils/peer-utils.d.ts +35 -0
- package/cjs/utils/peer-utils.js +188 -0
- package/cjs/utils/peer-utils.js.map +1 -0
- package/cjs/utils/platform/crypto.d.ts +1 -0
- package/cjs/utils/platform/crypto.js +8 -0
- package/cjs/utils/platform/crypto.js.map +1 -0
- package/cjs/utils/platform/crypto.web.d.ts +1 -0
- package/cjs/utils/platform/crypto.web.js +14 -0
- package/cjs/utils/platform/crypto.web.js.map +1 -0
- package/cjs/utils/platform/error-reporting.d.ts +3 -0
- package/cjs/utils/platform/error-reporting.js +22 -0
- package/cjs/utils/platform/error-reporting.js.map +1 -0
- package/cjs/utils/platform/logging.d.ts +1 -0
- package/cjs/utils/platform/logging.js +35 -0
- package/cjs/utils/platform/logging.js.map +1 -0
- package/cjs/utils/platform/logging.web.d.ts +1 -0
- package/cjs/utils/platform/logging.web.js +35 -0
- package/cjs/utils/platform/logging.web.js.map +1 -0
- package/cjs/utils/platform/random.d.ts +1 -0
- package/cjs/utils/platform/random.js +7 -0
- package/cjs/utils/platform/random.js.map +1 -0
- package/cjs/utils/platform/random.web.d.ts +1 -0
- package/cjs/utils/platform/random.web.js +10 -0
- package/cjs/utils/platform/random.web.js.map +1 -0
- package/cjs/utils/platform/transport.d.ts +1 -0
- package/cjs/utils/platform/transport.js +8 -0
- package/cjs/utils/platform/transport.js.map +1 -0
- package/cjs/utils/platform/transport.web.d.ts +1 -0
- package/cjs/utils/platform/transport.web.js +15 -0
- package/cjs/utils/platform/transport.web.js.map +1 -0
- package/cjs/utils/sorted-array.d.ts +17 -0
- package/cjs/utils/sorted-array.js +83 -0
- package/cjs/utils/sorted-array.js.map +1 -0
- package/cjs/utils/string-session.d.ts +11 -0
- package/cjs/utils/string-session.js +73 -0
- package/cjs/utils/string-session.js.map +1 -0
- package/cjs/utils/tl-json.d.ts +13 -0
- package/cjs/utils/tl-json.js +62 -0
- package/cjs/utils/tl-json.js.map +1 -0
- package/cjs/utils/type-assertions.d.ts +37 -0
- package/cjs/utils/type-assertions.js +70 -0
- package/cjs/utils/type-assertions.js.map +1 -0
- package/esm/base-client.d.ts +297 -0
- package/esm/base-client.js +317 -0
- package/esm/base-client.js.map +1 -0
- package/esm/index.d.ts +10 -0
- package/esm/index.js +11 -0
- package/esm/index.js.map +1 -0
- package/esm/network/auth-key.d.ts +21 -0
- package/esm/network/auth-key.js +97 -0
- package/esm/network/auth-key.js.map +1 -0
- package/esm/network/authorization.d.ts +9 -0
- package/esm/network/authorization.js +325 -0
- package/esm/network/authorization.js.map +1 -0
- package/esm/network/config-manager.d.ts +33 -0
- package/esm/network/config-manager.js +89 -0
- package/esm/network/config-manager.js.map +1 -0
- package/esm/network/index.d.ts +4 -0
- package/esm/network/index.js +4 -0
- package/esm/network/index.js.map +1 -0
- package/esm/network/mtproto-session.d.ts +116 -0
- package/esm/network/mtproto-session.js +202 -0
- package/esm/network/mtproto-session.js.map +1 -0
- package/esm/network/multi-session-connection.d.ts +33 -0
- package/esm/network/multi-session-connection.js +236 -0
- package/esm/network/multi-session-connection.js.map +1 -0
- package/esm/network/network-manager.d.ts +190 -0
- package/esm/network/network-manager.js +542 -0
- package/esm/network/network-manager.js.map +1 -0
- package/esm/network/persistent-connection.d.ts +51 -0
- package/esm/network/persistent-connection.js +166 -0
- package/esm/network/persistent-connection.js.map +1 -0
- package/esm/network/reconnection.d.ts +11 -0
- package/esm/network/reconnection.js +14 -0
- package/esm/network/reconnection.js.map +1 -0
- package/esm/network/session-connection.d.ts +72 -0
- package/esm/network/session-connection.js +1356 -0
- package/esm/network/session-connection.js.map +1 -0
- package/esm/network/transports/abstract.d.ts +99 -0
- package/esm/network/transports/abstract.js +34 -0
- package/esm/network/transports/abstract.js.map +1 -0
- package/esm/network/transports/index.d.ts +8 -0
- package/esm/network/transports/index.js +9 -0
- package/esm/network/transports/index.js.map +1 -0
- package/esm/network/transports/intermediate.d.ts +20 -0
- package/esm/network/transports/intermediate.js +62 -0
- package/esm/network/transports/intermediate.js.map +1 -0
- package/esm/network/transports/obfuscated.d.ts +18 -0
- package/esm/network/transports/obfuscated.js +79 -0
- package/esm/network/transports/obfuscated.js.map +1 -0
- package/esm/network/transports/streamed.d.ts +24 -0
- package/esm/network/transports/streamed.js +25 -0
- package/esm/network/transports/streamed.js.map +1 -0
- package/esm/network/transports/tcp.d.ts +33 -0
- package/esm/network/transports/tcp.js +122 -0
- package/esm/network/transports/tcp.js.map +1 -0
- package/esm/network/transports/websocket.d.ts +47 -0
- package/esm/network/transports/websocket.js +116 -0
- package/esm/network/transports/websocket.js.map +1 -0
- package/esm/network/transports/wrapped.d.ts +11 -0
- package/esm/network/transports/wrapped.js +19 -0
- package/esm/network/transports/wrapped.js.map +1 -0
- package/esm/storage/abstract.d.ts +174 -0
- package/esm/storage/abstract.js +2 -0
- package/esm/storage/abstract.js.map +1 -0
- package/esm/storage/index.d.ts +5 -0
- package/esm/storage/index.js +6 -0
- package/esm/storage/index.js.map +1 -0
- package/esm/storage/json-file.d.ts +31 -0
- package/esm/storage/json-file.js +63 -0
- package/esm/storage/json-file.js.map +1 -0
- package/esm/storage/json.d.ts +9 -0
- package/esm/storage/json.js +61 -0
- package/esm/storage/json.js.map +1 -0
- package/esm/storage/localstorage.d.ts +7 -0
- package/esm/storage/localstorage.js +21 -0
- package/esm/storage/localstorage.js.map +1 -0
- package/esm/storage/memory.d.ts +98 -0
- package/esm/storage/memory.js +295 -0
- package/esm/storage/memory.js.map +1 -0
- package/esm/types/errors.d.ts +53 -0
- package/esm/types/errors.js +49 -0
- package/esm/types/errors.js.map +1 -0
- package/esm/types/index.d.ts +3 -0
- package/esm/types/index.js +4 -0
- package/esm/types/index.js.map +1 -0
- package/esm/types/peers.d.ts +4 -0
- package/esm/types/peers.js +2 -0
- package/esm/types/peers.js.map +1 -0
- package/esm/types/utils.d.ts +6 -0
- package/esm/types/utils.js +5 -0
- package/esm/types/utils.js.map +1 -0
- package/esm/utils/async-lock.d.ts +10 -0
- package/esm/utils/async-lock.js +39 -0
- package/esm/utils/async-lock.js.map +1 -0
- package/esm/utils/bigint-utils.d.ts +40 -0
- package/esm/utils/bigint-utils.js +92 -0
- package/esm/utils/bigint-utils.js.map +1 -0
- package/esm/utils/binary/asn1-parser.d.ts +17 -0
- package/esm/utils/binary/asn1-parser.js +116 -0
- package/esm/utils/binary/asn1-parser.js.map +1 -0
- package/esm/utils/buffer-utils.d.ts +21 -0
- package/esm/utils/buffer-utils.js +55 -0
- package/esm/utils/buffer-utils.js.map +1 -0
- package/esm/utils/condition-variable.d.ts +9 -0
- package/esm/utils/condition-variable.js +24 -0
- package/esm/utils/condition-variable.js.map +1 -0
- package/esm/utils/controllable-promise.d.ts +16 -0
- package/esm/utils/controllable-promise.js +20 -0
- package/esm/utils/controllable-promise.js.map +1 -0
- package/esm/utils/crypto/abstract.d.ts +23 -0
- package/esm/utils/crypto/abstract.js +15 -0
- package/esm/utils/crypto/abstract.js.map +1 -0
- package/esm/utils/crypto/common.d.ts +12 -0
- package/esm/utils/crypto/common.js +50 -0
- package/esm/utils/crypto/common.js.map +1 -0
- package/esm/utils/crypto/factorization.d.ts +5 -0
- package/esm/utils/crypto/factorization.js +62 -0
- package/esm/utils/crypto/factorization.js.map +1 -0
- package/esm/utils/crypto/index.d.ts +5 -0
- package/esm/utils/crypto/index.js +6 -0
- package/esm/utils/crypto/index.js.map +1 -0
- package/esm/utils/crypto/keys.d.ts +27 -0
- package/esm/utils/crypto/keys.js +64 -0
- package/esm/utils/crypto/keys.js.map +1 -0
- package/esm/utils/crypto/miller-rabin.d.ts +2 -0
- package/esm/utils/crypto/miller-rabin.js +37 -0
- package/esm/utils/crypto/miller-rabin.js.map +1 -0
- package/esm/utils/crypto/mtproto.d.ts +31 -0
- package/esm/utils/crypto/mtproto.js +60 -0
- package/esm/utils/crypto/mtproto.js.map +1 -0
- package/esm/utils/crypto/node-crypto.d.ts +10 -0
- package/esm/utils/crypto/node-crypto.js +42 -0
- package/esm/utils/crypto/node-crypto.js.map +1 -0
- package/esm/utils/crypto/password.d.ts +29 -0
- package/esm/utils/crypto/password.js +97 -0
- package/esm/utils/crypto/password.js.map +1 -0
- package/esm/utils/crypto/subtle.d.ts +12 -0
- package/esm/utils/crypto/subtle.js +59 -0
- package/esm/utils/crypto/subtle.js.map +1 -0
- package/esm/utils/crypto/utils.d.ts +14 -0
- package/esm/utils/crypto/utils.js +25 -0
- package/esm/utils/crypto/utils.js.map +1 -0
- package/esm/utils/default-dcs.d.ts +7 -0
- package/esm/utils/default-dcs.js +73 -0
- package/esm/utils/default-dcs.js.map +1 -0
- package/esm/utils/deque.d.ts +29 -0
- package/esm/utils/deque.js +206 -0
- package/esm/utils/deque.js.map +1 -0
- package/esm/utils/early-timer.d.ts +42 -0
- package/esm/utils/early-timer.js +75 -0
- package/esm/utils/early-timer.js.map +1 -0
- package/esm/utils/flood-control.d.ts +14 -0
- package/esm/utils/flood-control.js +61 -0
- package/esm/utils/flood-control.js.map +1 -0
- package/esm/utils/function-utils.d.ts +13 -0
- package/esm/utils/function-utils.js +26 -0
- package/esm/utils/function-utils.js.map +1 -0
- package/esm/utils/index.d.ts +24 -0
- package/esm/utils/index.js +25 -0
- package/esm/utils/index.js.map +1 -0
- package/esm/utils/linked-list.d.ts +21 -0
- package/esm/utils/linked-list.js +69 -0
- package/esm/utils/linked-list.js.map +1 -0
- package/esm/utils/links/bots.d.ts +71 -0
- package/esm/utils/links/bots.js +256 -0
- package/esm/utils/links/bots.js.map +1 -0
- package/esm/utils/links/bundle.d.ts +7 -0
- package/esm/utils/links/bundle.js +8 -0
- package/esm/utils/links/bundle.js.map +1 -0
- package/esm/utils/links/calls.d.ts +16 -0
- package/esm/utils/links/calls.js +56 -0
- package/esm/utils/links/calls.js.map +1 -0
- package/esm/utils/links/chat.d.ts +46 -0
- package/esm/utils/links/chat.js +157 -0
- package/esm/utils/links/chat.js.map +1 -0
- package/esm/utils/links/common.d.ts +31 -0
- package/esm/utils/links/common.js +56 -0
- package/esm/utils/links/common.js.map +1 -0
- package/esm/utils/links/index.d.ts +2 -0
- package/esm/utils/links/index.js +3 -0
- package/esm/utils/links/index.js.map +1 -0
- package/esm/utils/links/misc.d.ts +19 -0
- package/esm/utils/links/misc.js +74 -0
- package/esm/utils/links/misc.js.map +1 -0
- package/esm/utils/links/proxy.d.ts +17 -0
- package/esm/utils/links/proxy.js +58 -0
- package/esm/utils/links/proxy.js.map +1 -0
- package/esm/utils/links/stickers.d.ts +9 -0
- package/esm/utils/links/stickers.js +25 -0
- package/esm/utils/links/stickers.js.map +1 -0
- package/esm/utils/links/user.d.ts +27 -0
- package/esm/utils/links/user.js +78 -0
- package/esm/utils/links/user.js.map +1 -0
- package/esm/utils/logger.d.ts +54 -0
- package/esm/utils/logger.js +154 -0
- package/esm/utils/logger.js.map +1 -0
- package/esm/utils/long-utils.d.ts +75 -0
- package/esm/utils/long-utils.js +148 -0
- package/esm/utils/long-utils.js.map +1 -0
- package/esm/utils/lru-map.d.ts +21 -0
- package/esm/utils/lru-map.js +103 -0
- package/esm/utils/lru-map.js.map +1 -0
- package/esm/utils/lru-set.d.ts +22 -0
- package/esm/utils/lru-set.js +44 -0
- package/esm/utils/lru-set.js.map +1 -0
- package/esm/utils/misc-utils.d.ts +7 -0
- package/esm/utils/misc-utils.js +10 -0
- package/esm/utils/misc-utils.js.map +1 -0
- package/esm/utils/peer-utils.d.ts +35 -0
- package/esm/utils/peer-utils.js +179 -0
- package/esm/utils/peer-utils.js.map +1 -0
- package/esm/utils/platform/crypto.d.ts +1 -0
- package/esm/utils/platform/crypto.js +4 -0
- package/esm/utils/platform/crypto.js.map +1 -0
- package/esm/utils/platform/crypto.web.d.ts +1 -0
- package/esm/utils/platform/crypto.web.js +10 -0
- package/esm/utils/platform/crypto.web.js.map +1 -0
- package/esm/utils/platform/error-reporting.d.ts +3 -0
- package/esm/utils/platform/error-reporting.js +18 -0
- package/esm/utils/platform/error-reporting.js.map +1 -0
- package/esm/utils/platform/logging.d.ts +1 -0
- package/esm/utils/platform/logging.js +32 -0
- package/esm/utils/platform/logging.js.map +1 -0
- package/esm/utils/platform/logging.web.d.ts +1 -0
- package/esm/utils/platform/logging.web.js +31 -0
- package/esm/utils/platform/logging.web.js.map +1 -0
- package/esm/utils/platform/random.d.ts +1 -0
- package/esm/utils/platform/random.js +4 -0
- package/esm/utils/platform/random.js.map +1 -0
- package/esm/utils/platform/random.web.d.ts +1 -0
- package/esm/utils/platform/random.web.js +6 -0
- package/esm/utils/platform/random.web.js.map +1 -0
- package/esm/utils/platform/transport.d.ts +1 -0
- package/esm/utils/platform/transport.js +4 -0
- package/esm/utils/platform/transport.js.map +1 -0
- package/esm/utils/platform/transport.web.d.ts +1 -0
- package/esm/utils/platform/transport.web.js +12 -0
- package/esm/utils/platform/transport.web.js.map +1 -0
- package/esm/utils/sorted-array.d.ts +17 -0
- package/esm/utils/sorted-array.js +79 -0
- package/esm/utils/sorted-array.js.map +1 -0
- package/esm/utils/string-session.d.ts +11 -0
- package/esm/utils/string-session.js +68 -0
- package/esm/utils/string-session.js.map +1 -0
- package/esm/utils/tl-json.d.ts +13 -0
- package/esm/utils/tl-json.js +57 -0
- package/esm/utils/tl-json.js.map +1 -0
- package/esm/utils/type-assertions.d.ts +37 -0
- package/esm/utils/type-assertions.js +61 -0
- package/esm/utils/type-assertions.js.map +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { LongSet } from './long-utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Simple class implementing LRU-like behaviour for a Set.
|
|
4
|
+
*
|
|
5
|
+
* Note: this is not exactly LRU, but rather "least recently added"
|
|
6
|
+
* and doesn't mark items as recently added if they are already in the set.
|
|
7
|
+
* This is enough for our use case, so we don't bother with more complex implementation.
|
|
8
|
+
*
|
|
9
|
+
* Used to store recently received message IDs in {@link SessionConnection}
|
|
10
|
+
*
|
|
11
|
+
* Uses one-way linked list internally to keep track of insertion order
|
|
12
|
+
*/
|
|
13
|
+
export class LruSet {
|
|
14
|
+
constructor(capacity, forLong = false) {
|
|
15
|
+
this._capacity = capacity;
|
|
16
|
+
this._set = forLong ? new LongSet() : new Set();
|
|
17
|
+
}
|
|
18
|
+
clear() {
|
|
19
|
+
this._first = this._last = undefined;
|
|
20
|
+
this._set.clear();
|
|
21
|
+
}
|
|
22
|
+
add(val) {
|
|
23
|
+
if (this._set.has(val))
|
|
24
|
+
return;
|
|
25
|
+
if (!this._first)
|
|
26
|
+
this._first = { v: val };
|
|
27
|
+
if (!this._last)
|
|
28
|
+
this._last = this._first;
|
|
29
|
+
else {
|
|
30
|
+
this._last.n = { v: val };
|
|
31
|
+
this._last = this._last.n;
|
|
32
|
+
}
|
|
33
|
+
this._set.add(val);
|
|
34
|
+
if (this._set.size > this._capacity && this._first) {
|
|
35
|
+
// remove least recently used
|
|
36
|
+
this._set.delete(this._first.v);
|
|
37
|
+
this._first = this._first.n;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
has(val) {
|
|
41
|
+
return this._set.has(val);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=lru-set.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lru-set.js","sourceRoot":"","sources":["../../../src/utils/lru-set.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAOzC;;;;;;;;;;GAUG;AACH,MAAM,OAAO,MAAM;IAOf,YAAY,QAAgB,EAAE,OAAO,GAAG,KAAK;QACzC,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAA;QAEzB,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAA;IACnD,CAAC;IAED,KAAK;QACD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,GAAG,SAAS,CAAA;QACpC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAA;IACrB,CAAC;IAED,GAAG,CAAC,GAAM;QACN,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAU,CAAC;YAAE,OAAM;QAErC,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAA;QAE1C,IAAI,CAAC,IAAI,CAAC,KAAK;YAAE,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,CAAA;aACpC;YACD,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAA;YACzB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;SAC5B;QAED,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAU,CAAC,CAAA;QAEzB,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,MAAM,EAAE;YAChD,6BAA6B;YAC7B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAQ,CAAC,CAAA;YACtC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAA;SAC9B;IACL,CAAC;IAED,GAAG,CAAC,GAAM;QACN,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAU,CAAC,CAAA;IACpC,CAAC;CACJ","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-argument */\n// ^^ because of performance reasons\nimport Long from 'long'\n\nimport { LongSet } from './long-utils.js'\n\ninterface OneWayLinkedList<T> {\n v: T\n n?: OneWayLinkedList<T>\n}\n\n/**\n * Simple class implementing LRU-like behaviour for a Set.\n *\n * Note: this is not exactly LRU, but rather \"least recently added\"\n * and doesn't mark items as recently added if they are already in the set.\n * This is enough for our use case, so we don't bother with more complex implementation.\n *\n * Used to store recently received message IDs in {@link SessionConnection}\n *\n * Uses one-way linked list internally to keep track of insertion order\n */\nexport class LruSet<T extends string | number | Long> {\n private _capacity: number\n private _first?: OneWayLinkedList<T>\n private _last?: OneWayLinkedList<T>\n\n private _set: Set<T> | LongSet\n\n constructor(capacity: number, forLong = false) {\n this._capacity = capacity\n\n this._set = forLong ? new LongSet() : new Set()\n }\n\n clear() {\n this._first = this._last = undefined\n this._set.clear()\n }\n\n add(val: T) {\n if (this._set.has(val as any)) return\n\n if (!this._first) this._first = { v: val }\n\n if (!this._last) this._last = this._first\n else {\n this._last.n = { v: val }\n this._last = this._last.n\n }\n\n this._set.add(val as any)\n\n if (this._set.size > this._capacity && this._first) {\n // remove least recently used\n this._set.delete(this._first.v as any)\n this._first = this._first.n\n }\n }\n\n has(val: T) {\n return this._set.has(val as any)\n }\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sleep for the given number of ms
|
|
3
|
+
*
|
|
4
|
+
* @param ms Number of ms to sleep
|
|
5
|
+
*/
|
|
6
|
+
export const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
7
|
+
export function getRandomInt(top) {
|
|
8
|
+
return Math.floor(Math.random() * top);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=misc-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"misc-utils.js","sourceRoot":"","sources":["../../../src/utils/misc-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,EAAU,EAAiB,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAA;AAErG,MAAM,UAAU,YAAY,CAAC,GAAW;IACpC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAA;AAC1C,CAAC","sourcesContent":["/**\n * Sleep for the given number of ms\n *\n * @param ms Number of ms to sleep\n */\nexport const sleep = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms))\n\nexport function getRandomInt(top: number): number {\n return Math.floor(Math.random() * top)\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { tl } from '@mtcute/tl';
|
|
2
|
+
import { BasicPeerType } from '../types/peers.js';
|
|
3
|
+
/**
|
|
4
|
+
* Add or remove channel marker from ID
|
|
5
|
+
*/
|
|
6
|
+
export declare function toggleChannelIdMark(id: number): number;
|
|
7
|
+
/**
|
|
8
|
+
* Get the bare (non-marked) ID from a {@link tl.TypePeer}
|
|
9
|
+
*/
|
|
10
|
+
export declare function getBarePeerId(peer: tl.TypePeer): number;
|
|
11
|
+
/**
|
|
12
|
+
* Get the marked (non-bare) ID from a {@link tl.TypePeer}
|
|
13
|
+
*
|
|
14
|
+
* *Mark* is bot API compatible, which is:
|
|
15
|
+
* - ID stays the same for users
|
|
16
|
+
* - ID is negated for chats
|
|
17
|
+
* - ID is negated and `-1e12` is subtracted for channels
|
|
18
|
+
*/
|
|
19
|
+
export declare function getMarkedPeerId(peerId: number, peerType: BasicPeerType): number;
|
|
20
|
+
export declare function getMarkedPeerId(peer: tl.TypePeer | tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel): number;
|
|
21
|
+
/**
|
|
22
|
+
* Extract basic peer type from {@link tl.TypePeer} or its marked ID.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getBasicPeerType(peer: tl.TypePeer | number): BasicPeerType;
|
|
25
|
+
/**
|
|
26
|
+
* Extract bare peer ID from marked ID.
|
|
27
|
+
*
|
|
28
|
+
* @param peerId Marked peer ID
|
|
29
|
+
*/
|
|
30
|
+
export declare function markedPeerIdToBare(peerId: number): number;
|
|
31
|
+
/**
|
|
32
|
+
* Extracts all (cacheable) entities from a TlObject or a list of them.
|
|
33
|
+
* Only checks `.user`, `.chat`, `.channel`, `.users` and `.chats` properties
|
|
34
|
+
*/
|
|
35
|
+
export declare function getAllPeersFrom(obj: tl.TlObject | tl.TlObject[]): Iterable<tl.TypeUser | tl.TypeChat>;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { MtArgumentError, MtUnsupportedError } from '../types/errors.js';
|
|
2
|
+
// src: https://github.com/tdlib/td/blob/master/td/telegram/DialogId.h
|
|
3
|
+
const ZERO_CHANNEL_ID = -1000000000000;
|
|
4
|
+
const ZERO_SECRET_CHAT_ID = -2000000000000;
|
|
5
|
+
const MAX_SECRET_CHAT_ID = -1997852516353; // ZERO_SECRET_CHAT_ID + 0x7fffffff
|
|
6
|
+
// src: https://github.com/tdlib/td/blob/master/td/telegram/ChatId.h
|
|
7
|
+
// const MAX_CHAT_ID = 999999999999
|
|
8
|
+
const MIN_MARKED_CHAT_ID = -999999999999; // -MAX_CHAT_ID
|
|
9
|
+
// src: https://github.com/tdlib/td/blob/master/td/telegram/UserId.h
|
|
10
|
+
// MAX_USER_ID = (1ll << 40) - 1
|
|
11
|
+
const MAX_USER_ID = 1099511627775;
|
|
12
|
+
// src: https://github.com/tdlib/td/blob/master/td/telegram/ChannelId.h
|
|
13
|
+
// the last (1 << 31) - 1 identifiers will be used for secret chat dialog identifiers
|
|
14
|
+
// MAX_CHANNEL_ID = 1000000000000ll - (1ll << 31)
|
|
15
|
+
// const MAX_CHANNEL_ID = 997852516352
|
|
16
|
+
const MIN_MARKED_CHANNEL_ID = -1997852516352; // ZERO_CHANNEL_ID - MAX_CHANNEL_ID
|
|
17
|
+
/**
|
|
18
|
+
* Add or remove channel marker from ID
|
|
19
|
+
*/
|
|
20
|
+
export function toggleChannelIdMark(id) {
|
|
21
|
+
return ZERO_CHANNEL_ID - id;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get the bare (non-marked) ID from a {@link tl.TypePeer}
|
|
25
|
+
*/
|
|
26
|
+
export function getBarePeerId(peer) {
|
|
27
|
+
switch (peer._) {
|
|
28
|
+
case 'peerUser':
|
|
29
|
+
return peer.userId;
|
|
30
|
+
case 'peerChat':
|
|
31
|
+
return peer.chatId;
|
|
32
|
+
case 'peerChannel':
|
|
33
|
+
return peer.channelId;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export function getMarkedPeerId(peer, peerType) {
|
|
37
|
+
if (typeof peer === 'number') {
|
|
38
|
+
switch (peerType) {
|
|
39
|
+
case 'user':
|
|
40
|
+
return peer;
|
|
41
|
+
case 'chat':
|
|
42
|
+
return -peer;
|
|
43
|
+
case 'channel':
|
|
44
|
+
return ZERO_CHANNEL_ID - peer;
|
|
45
|
+
}
|
|
46
|
+
throw new MtArgumentError('Invalid peer type');
|
|
47
|
+
}
|
|
48
|
+
switch (peer._) {
|
|
49
|
+
case 'peerUser':
|
|
50
|
+
case 'inputPeerUser':
|
|
51
|
+
case 'inputUser':
|
|
52
|
+
return peer.userId;
|
|
53
|
+
case 'peerChat':
|
|
54
|
+
case 'inputPeerChat':
|
|
55
|
+
return -peer.chatId;
|
|
56
|
+
case 'peerChannel':
|
|
57
|
+
case 'inputPeerChannel':
|
|
58
|
+
case 'inputChannel':
|
|
59
|
+
return ZERO_CHANNEL_ID - peer.channelId;
|
|
60
|
+
}
|
|
61
|
+
throw new MtArgumentError('Invalid peer');
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Extract basic peer type from {@link tl.TypePeer} or its marked ID.
|
|
65
|
+
*/
|
|
66
|
+
export function getBasicPeerType(peer) {
|
|
67
|
+
if (typeof peer !== 'number') {
|
|
68
|
+
switch (peer._) {
|
|
69
|
+
case 'peerUser':
|
|
70
|
+
return 'user';
|
|
71
|
+
case 'peerChat':
|
|
72
|
+
return 'chat';
|
|
73
|
+
case 'peerChannel':
|
|
74
|
+
return 'channel';
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (peer < 0) {
|
|
78
|
+
if (MIN_MARKED_CHAT_ID <= peer) {
|
|
79
|
+
return 'chat';
|
|
80
|
+
}
|
|
81
|
+
if (MIN_MARKED_CHANNEL_ID <= peer && peer !== ZERO_CHANNEL_ID) {
|
|
82
|
+
return 'channel';
|
|
83
|
+
}
|
|
84
|
+
if (MAX_SECRET_CHAT_ID <= peer && peer !== ZERO_SECRET_CHAT_ID) {
|
|
85
|
+
// return 'secret'
|
|
86
|
+
throw new MtUnsupportedError('Secret chats are not supported');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else if (peer > 0 && peer <= MAX_USER_ID) {
|
|
90
|
+
return 'user';
|
|
91
|
+
}
|
|
92
|
+
throw new MtArgumentError(`Invalid marked peer id: ${peer}`);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Extract bare peer ID from marked ID.
|
|
96
|
+
*
|
|
97
|
+
* @param peerId Marked peer ID
|
|
98
|
+
*/
|
|
99
|
+
export function markedPeerIdToBare(peerId) {
|
|
100
|
+
const type = getBasicPeerType(peerId);
|
|
101
|
+
switch (type) {
|
|
102
|
+
case 'user':
|
|
103
|
+
return peerId;
|
|
104
|
+
case 'chat':
|
|
105
|
+
return -peerId;
|
|
106
|
+
case 'channel':
|
|
107
|
+
return toggleChannelIdMark(peerId);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Extracts all (cacheable) entities from a TlObject or a list of them.
|
|
112
|
+
* Only checks `.user`, `.chat`, `.channel`, `.users` and `.chats` properties
|
|
113
|
+
*/
|
|
114
|
+
export function* getAllPeersFrom(obj) {
|
|
115
|
+
if (typeof obj !== 'object')
|
|
116
|
+
return;
|
|
117
|
+
if (Array.isArray(obj)) {
|
|
118
|
+
for (const it of obj) {
|
|
119
|
+
yield* getAllPeersFrom(it);
|
|
120
|
+
}
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
switch (obj._) {
|
|
124
|
+
case 'user':
|
|
125
|
+
case 'chat':
|
|
126
|
+
case 'channel':
|
|
127
|
+
case 'chatForbidden':
|
|
128
|
+
case 'channelForbidden':
|
|
129
|
+
yield obj;
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if ('user' in obj && typeof obj.user === 'object' && obj.user._ === 'user') {
|
|
133
|
+
yield obj.user;
|
|
134
|
+
}
|
|
135
|
+
if ('chat' in obj && typeof obj.chat === 'object') {
|
|
136
|
+
switch (obj.chat._) {
|
|
137
|
+
case 'chat':
|
|
138
|
+
case 'channel':
|
|
139
|
+
case 'chatForbidden':
|
|
140
|
+
case 'channelForbidden':
|
|
141
|
+
yield obj.chat;
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if ('channel' in obj && typeof obj.channel === 'object') {
|
|
146
|
+
switch (obj.channel._) {
|
|
147
|
+
case 'chat':
|
|
148
|
+
case 'channel':
|
|
149
|
+
case 'chatForbidden':
|
|
150
|
+
case 'channelForbidden':
|
|
151
|
+
yield obj.channel;
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if ('users' in obj && Array.isArray(obj.users) && obj.users.length) {
|
|
156
|
+
for (const user of obj.users) {
|
|
157
|
+
// .users is sometimes number[]
|
|
158
|
+
if (typeof user === 'object' && user._ === 'user') {
|
|
159
|
+
yield user;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if ('chats' in obj && Array.isArray(obj.chats) && obj.chats.length) {
|
|
164
|
+
for (const chat of obj.chats) {
|
|
165
|
+
// .chats is sometimes number[]
|
|
166
|
+
if (typeof chat === 'object') {
|
|
167
|
+
switch (chat._) {
|
|
168
|
+
case 'chat':
|
|
169
|
+
case 'channel':
|
|
170
|
+
case 'chatForbidden':
|
|
171
|
+
case 'channelForbidden':
|
|
172
|
+
yield chat;
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=peer-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"peer-utils.js","sourceRoot":"","sources":["../../../src/utils/peer-utils.ts"],"names":[],"mappings":"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","sourcesContent":["import { tl } from '@mtcute/tl'\n\nimport { MtArgumentError, MtUnsupportedError } from '../types/errors.js'\nimport { BasicPeerType } from '../types/peers.js'\n\n// src: https://github.com/tdlib/td/blob/master/td/telegram/DialogId.h\nconst ZERO_CHANNEL_ID = -1000000000000\nconst ZERO_SECRET_CHAT_ID = -2000000000000\nconst MAX_SECRET_CHAT_ID = -1997852516353 // ZERO_SECRET_CHAT_ID + 0x7fffffff\n// src: https://github.com/tdlib/td/blob/master/td/telegram/ChatId.h\n// const MAX_CHAT_ID = 999999999999\nconst MIN_MARKED_CHAT_ID = -999999999999 // -MAX_CHAT_ID\n// src: https://github.com/tdlib/td/blob/master/td/telegram/UserId.h\n// MAX_USER_ID = (1ll << 40) - 1\nconst MAX_USER_ID = 1099511627775\n// src: https://github.com/tdlib/td/blob/master/td/telegram/ChannelId.h\n// the last (1 << 31) - 1 identifiers will be used for secret chat dialog identifiers\n// MAX_CHANNEL_ID = 1000000000000ll - (1ll << 31)\n// const MAX_CHANNEL_ID = 997852516352\nconst MIN_MARKED_CHANNEL_ID = -1997852516352 // ZERO_CHANNEL_ID - MAX_CHANNEL_ID\n\n/**\n * Add or remove channel marker from ID\n */\nexport function toggleChannelIdMark(id: number): number {\n return ZERO_CHANNEL_ID - id\n}\n\n/**\n * Get the bare (non-marked) ID from a {@link tl.TypePeer}\n */\nexport function getBarePeerId(peer: tl.TypePeer): number {\n switch (peer._) {\n case 'peerUser':\n return peer.userId\n case 'peerChat':\n return peer.chatId\n case 'peerChannel':\n return peer.channelId\n }\n}\n\n// src: https://github.com/tdlib/td/blob/master/td/telegram/DialogId.cpp\n\n/**\n * Get the marked (non-bare) ID from a {@link tl.TypePeer}\n *\n * *Mark* is bot API compatible, which is:\n * - ID stays the same for users\n * - ID is negated for chats\n * - ID is negated and `-1e12` is subtracted for channels\n */\nexport function getMarkedPeerId(peerId: number, peerType: BasicPeerType): number\nexport function getMarkedPeerId(peer: tl.TypePeer | tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel): number\n\nexport function getMarkedPeerId(\n peer: tl.TypePeer | tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel | number,\n peerType?: BasicPeerType,\n): number {\n if (typeof peer === 'number') {\n switch (peerType) {\n case 'user':\n return peer\n case 'chat':\n return -peer\n case 'channel':\n return ZERO_CHANNEL_ID - peer\n }\n throw new MtArgumentError('Invalid peer type')\n }\n\n switch (peer._) {\n case 'peerUser':\n case 'inputPeerUser':\n case 'inputUser':\n return peer.userId\n case 'peerChat':\n case 'inputPeerChat':\n return -peer.chatId\n case 'peerChannel':\n case 'inputPeerChannel':\n case 'inputChannel':\n return ZERO_CHANNEL_ID - peer.channelId\n }\n\n throw new MtArgumentError('Invalid peer')\n}\n\n/**\n * Extract basic peer type from {@link tl.TypePeer} or its marked ID.\n */\nexport function getBasicPeerType(peer: tl.TypePeer | number): BasicPeerType {\n if (typeof peer !== 'number') {\n switch (peer._) {\n case 'peerUser':\n return 'user'\n case 'peerChat':\n return 'chat'\n case 'peerChannel':\n return 'channel'\n }\n }\n\n if (peer < 0) {\n if (MIN_MARKED_CHAT_ID <= peer) {\n return 'chat'\n }\n\n if (MIN_MARKED_CHANNEL_ID <= peer && peer !== ZERO_CHANNEL_ID) {\n return 'channel'\n }\n\n if (MAX_SECRET_CHAT_ID <= peer && peer !== ZERO_SECRET_CHAT_ID) {\n // return 'secret'\n throw new MtUnsupportedError('Secret chats are not supported')\n }\n } else if (peer > 0 && peer <= MAX_USER_ID) {\n return 'user'\n }\n\n throw new MtArgumentError(`Invalid marked peer id: ${peer}`)\n}\n\n/**\n * Extract bare peer ID from marked ID.\n *\n * @param peerId Marked peer ID\n */\nexport function markedPeerIdToBare(peerId: number): number {\n const type = getBasicPeerType(peerId)\n\n switch (type) {\n case 'user':\n return peerId\n case 'chat':\n return -peerId\n case 'channel':\n return toggleChannelIdMark(peerId)\n }\n}\n\n/**\n * Extracts all (cacheable) entities from a TlObject or a list of them.\n * Only checks `.user`, `.chat`, `.channel`, `.users` and `.chats` properties\n */\nexport function* getAllPeersFrom(obj: tl.TlObject | tl.TlObject[]): Iterable<tl.TypeUser | tl.TypeChat> {\n if (typeof obj !== 'object') return\n\n if (Array.isArray(obj)) {\n for (const it of obj) {\n yield* getAllPeersFrom(it)\n }\n\n return\n }\n\n switch (obj._) {\n case 'user':\n case 'chat':\n case 'channel':\n case 'chatForbidden':\n case 'channelForbidden':\n yield obj\n\n return\n }\n\n if ('user' in obj && typeof obj.user === 'object' && obj.user._ === 'user') {\n yield obj.user\n }\n\n if ('chat' in obj && typeof obj.chat === 'object') {\n switch (obj.chat._) {\n case 'chat':\n case 'channel':\n case 'chatForbidden':\n case 'channelForbidden':\n yield obj.chat\n break\n }\n }\n\n if ('channel' in obj && typeof obj.channel === 'object') {\n switch (obj.channel._) {\n case 'chat':\n case 'channel':\n case 'chatForbidden':\n case 'channelForbidden':\n yield obj.channel\n break\n }\n }\n\n if ('users' in obj && Array.isArray(obj.users) && obj.users.length) {\n for (const user of obj.users) {\n // .users is sometimes number[]\n if (typeof user === 'object' && user._ === 'user') {\n yield user\n }\n }\n }\n\n if ('chats' in obj && Array.isArray(obj.chats) && obj.chats.length) {\n for (const chat of obj.chats) {\n // .chats is sometimes number[]\n if (typeof chat === 'object') {\n switch (chat._) {\n case 'chat':\n case 'channel':\n case 'chatForbidden':\n case 'channelForbidden':\n yield chat\n break\n }\n }\n }\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../../../src/utils/platform/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAE7D,gBAAgB;AAChB,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAAG,EAAE,CAAC,IAAI,kBAAkB,EAAE,CAAA","sourcesContent":["import { NodeCryptoProvider } from '../crypto/node-crypto.js'\n\n/** @internal */\nexport const _defaultCryptoProviderFactory = () => new NodeCryptoProvider()\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MtUnsupportedError } from '../../index.js';
|
|
2
|
+
import { SubtleCryptoProvider } from '../crypto/subtle.js';
|
|
3
|
+
/** @internal */
|
|
4
|
+
export const _defaultCryptoProviderFactory = () => {
|
|
5
|
+
if (typeof crypto === 'undefined' || typeof crypto.subtle === 'undefined') {
|
|
6
|
+
throw new MtUnsupportedError('WebCrypto API is not available');
|
|
7
|
+
}
|
|
8
|
+
return new SubtleCryptoProvider(crypto.subtle);
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=crypto.web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.web.js","sourceRoot":"","sources":["../../../../src/utils/platform/crypto.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAE1D,gBAAgB;AAChB,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAAG,EAAE;IAC9C,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,MAAM,KAAK,WAAW,EAAE;QACvE,MAAM,IAAI,kBAAkB,CAAC,gCAAgC,CAAC,CAAA;KACjE;IAED,OAAO,IAAI,oBAAoB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;AAClD,CAAC,CAAA","sourcesContent":["import { MtUnsupportedError } from '../../index.js'\nimport { SubtleCryptoProvider } from '../crypto/subtle.js'\n\n/** @internal */\nexport const _defaultCryptoProviderFactory = () => {\n if (typeof crypto === 'undefined' || typeof crypto.subtle === 'undefined') {\n throw new MtUnsupportedError('WebCrypto API is not available')\n }\n\n return new SubtleCryptoProvider(crypto.subtle)\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function reportUnknownError(log, error, method) {
|
|
2
|
+
if (typeof fetch !== 'function')
|
|
3
|
+
return;
|
|
4
|
+
fetch(`https://rpc.pwrtelegram.xyz/?code=${error.code}&method=${method}&error=${error.text}`)
|
|
5
|
+
.then((r) => r.json())
|
|
6
|
+
.then((r) => {
|
|
7
|
+
if (r.ok) {
|
|
8
|
+
log.info('telerpc responded with error info for %s: %s', error.text, r.result);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
log.info('Reported error %s to telerpc. You can disable this using `enableErrorReporting: false`', error.text);
|
|
12
|
+
}
|
|
13
|
+
})
|
|
14
|
+
.catch((e) => {
|
|
15
|
+
log.debug('failed to report error %s to telerpc: %s', error.text, e);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=error-reporting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-reporting.js","sourceRoot":"","sources":["../../../../src/utils/platform/error-reporting.ts"],"names":[],"mappings":"AAIA,MAAM,UAAU,kBAAkB,CAAC,GAAW,EAAE,KAAkB,EAAE,MAAc;IAC9E,IAAI,OAAO,KAAK,KAAK,UAAU;QAAE,OAAM;IAEvC,KAAK,CAAC,qCAAqC,KAAK,CAAC,IAAI,WAAW,MAAM,UAAU,KAAK,CAAC,IAAI,EAAE,CAAC;SACxF,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SACrB,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;QACR,IAAI,CAAC,CAAC,EAAE,EAAE;YACN,GAAG,CAAC,IAAI,CAAC,8CAA8C,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAA;SACjF;aAAM;YACH,GAAG,CAAC,IAAI,CACJ,wFAAwF,EACxF,KAAK,CAAC,IAAI,CACb,CAAA;SACJ;IACL,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;QACT,GAAG,CAAC,KAAK,CAAC,0CAA0C,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;IACxE,CAAC,CAAC,CAAA;AACV,CAAC","sourcesContent":["import { tl } from '@mtcute/tl'\n\nimport { Logger } from '../logger.js'\n\nexport function reportUnknownError(log: Logger, error: tl.RpcError, method: string): void {\n if (typeof fetch !== 'function') return\n\n fetch(`https://rpc.pwrtelegram.xyz/?code=${error.code}&method=${method}&error=${error.text}`)\n .then((r) => r.json())\n .then((r) => {\n if (r.ok) {\n log.info('telerpc responded with error info for %s: %s', error.text, r.result)\n } else {\n log.info(\n 'Reported error %s to telerpc. You can disable this using `enableErrorReporting: false`',\n error.text,\n )\n }\n })\n .catch((e) => {\n log.debug('failed to report error %s to telerpc: %s', error.text, e)\n })\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { isatty } from 'tty';
|
|
2
|
+
const isTty = isatty(process.stdout.fd);
|
|
3
|
+
const BASE_FORMAT = isTty ? '%s [%s] [%s%s\x1b[0m] ' : '%s [%s] [%s] ';
|
|
4
|
+
const LEVEL_NAMES = isTty ?
|
|
5
|
+
[
|
|
6
|
+
'',
|
|
7
|
+
'\x1b[31mERR\x1b[0m',
|
|
8
|
+
'\x1b[33mWRN\x1b[0m',
|
|
9
|
+
'\x1b[34mINF\x1b[0m',
|
|
10
|
+
'\x1b[36mDBG\x1b[0m',
|
|
11
|
+
'\x1b[35mVRB\x1b[0m',
|
|
12
|
+
] :
|
|
13
|
+
[
|
|
14
|
+
'',
|
|
15
|
+
'ERR',
|
|
16
|
+
'WRN',
|
|
17
|
+
'INF',
|
|
18
|
+
'DBG',
|
|
19
|
+
'VRB',
|
|
20
|
+
];
|
|
21
|
+
const TAG_COLORS = [6, 2, 3, 4, 5, 1].map((i) => `\x1b[3${i};1m`);
|
|
22
|
+
/** @internal */
|
|
23
|
+
export const _defaultLoggingHandler = isTty ?
|
|
24
|
+
(color, level, tag, fmt, args) => {
|
|
25
|
+
// eslint-disable-next-line no-console
|
|
26
|
+
console.log(BASE_FORMAT + fmt, new Date().toISOString(), LEVEL_NAMES[level], TAG_COLORS[color], tag, ...args);
|
|
27
|
+
} :
|
|
28
|
+
(color, level, tag, fmt, args) => {
|
|
29
|
+
// eslint-disable-next-line no-console
|
|
30
|
+
console.log(BASE_FORMAT + fmt, new Date().toISOString(), LEVEL_NAMES[level], tag, ...args);
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=logging.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logging.js","sourceRoot":"","sources":["../../../../src/utils/platform/logging.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAA;AAE5B,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;AAEvC,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,eAAe,CAAA;AACtE,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC;IACvB;QACI,EAAE;QACF,oBAAoB;QACpB,oBAAoB;QACpB,oBAAoB;QACpB,oBAAoB;QACpB,oBAAoB;KACvB,CAAC,CAAC;IACH;QACI,EAAE;QACF,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;KACR,CAAA;AACL,MAAM,UAAU,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;AAEjE,gBAAgB;AAChB,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,CAAC,CAAC;IACzC,CAAC,KAAa,EAAE,KAAa,EAAE,GAAW,EAAE,GAAW,EAAE,IAAe,EAAQ,EAAE;QAC9E,sCAAsC;QACtC,OAAO,CAAC,GAAG,CAAC,WAAW,GAAG,GAAG,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;IACjH,CAAC,CAAC,CAAC;IACH,CAAC,KAAa,EAAE,KAAa,EAAE,GAAW,EAAE,GAAW,EAAE,IAAe,EAAQ,EAAE;QAC9E,sCAAsC;QACtC,OAAO,CAAC,GAAG,CAAC,WAAW,GAAG,GAAG,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;IAC9F,CAAC,CAAA","sourcesContent":["import { isatty } from 'tty'\n\nconst isTty = isatty(process.stdout.fd)\n\nconst BASE_FORMAT = isTty ? '%s [%s] [%s%s\\x1b[0m] ' : '%s [%s] [%s] '\nconst LEVEL_NAMES = isTty ?\n [\n '', // OFF\n '\\x1b[31mERR\\x1b[0m',\n '\\x1b[33mWRN\\x1b[0m',\n '\\x1b[34mINF\\x1b[0m',\n '\\x1b[36mDBG\\x1b[0m',\n '\\x1b[35mVRB\\x1b[0m',\n ] :\n [\n '', // OFF\n 'ERR',\n 'WRN',\n 'INF',\n 'DBG',\n 'VRB',\n ]\nconst TAG_COLORS = [6, 2, 3, 4, 5, 1].map((i) => `\\x1b[3${i};1m`)\n\n/** @internal */\nexport const _defaultLoggingHandler = isTty ?\n (color: number, level: number, tag: string, fmt: string, args: unknown[]): void => {\n // eslint-disable-next-line no-console\n console.log(BASE_FORMAT + fmt, new Date().toISOString(), LEVEL_NAMES[level], TAG_COLORS[color], tag, ...args)\n } :\n (color: number, level: number, tag: string, fmt: string, args: unknown[]): void => {\n // eslint-disable-next-line no-console\n console.log(BASE_FORMAT + fmt, new Date().toISOString(), LEVEL_NAMES[level], tag, ...args)\n }\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const BASE_FORMAT = '%s [%c%s%c] [%c%s%c] ';
|
|
2
|
+
const LEVEL_NAMES = [
|
|
3
|
+
'',
|
|
4
|
+
'ERR',
|
|
5
|
+
'WRN',
|
|
6
|
+
'INF',
|
|
7
|
+
'DBG',
|
|
8
|
+
'VRB',
|
|
9
|
+
];
|
|
10
|
+
const COLORS = [
|
|
11
|
+
'',
|
|
12
|
+
'color: #7a5f9d',
|
|
13
|
+
'color: #8d7041',
|
|
14
|
+
'color: #396c9e',
|
|
15
|
+
'color: #437761',
|
|
16
|
+
'color: #7a5f9d',
|
|
17
|
+
];
|
|
18
|
+
const TAG_COLORS = [
|
|
19
|
+
'color: #437761',
|
|
20
|
+
'color: #537a36',
|
|
21
|
+
'color: #8d7041',
|
|
22
|
+
'color: #396c9e',
|
|
23
|
+
'color: #7a5f9d',
|
|
24
|
+
'color: #7a5f9d',
|
|
25
|
+
];
|
|
26
|
+
/** @internal */
|
|
27
|
+
export const _defaultLoggingHandler = (color, level, tag, fmt, args) => {
|
|
28
|
+
// eslint-disable-next-line no-console
|
|
29
|
+
console.log(BASE_FORMAT + fmt, new Date().toISOString(), COLORS[level], LEVEL_NAMES[level], '', TAG_COLORS[color], tag, '', ...args);
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=logging.web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logging.web.js","sourceRoot":"","sources":["../../../../src/utils/platform/logging.web.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG,uBAAuB,CAAA;AAC3C,MAAM,WAAW,GAAG;IAChB,EAAE;IACF,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;CACR,CAAA;AACD,MAAM,MAAM,GAAG;IACX,EAAE;IACF,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;CACnB,CAAA;AACD,MAAM,UAAU,GAAG;IACf,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;CACnB,CAAA;AAED,gBAAgB;AAChB,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAClC,KAAa,EACb,KAAa,EACb,GAAW,EACX,GAAW,EACX,IAAe,EACX,EAAE;IACN,sCAAsC;IACtC,OAAO,CAAC,GAAG,CACP,WAAW,GAAG,GAAG,EACjB,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EACxB,MAAM,CAAC,KAAK,CAAC,EACb,WAAW,CAAC,KAAK,CAAC,EAClB,EAAE,EACF,UAAU,CAAC,KAAK,CAAC,EACjB,GAAG,EACH,EAAE,EACF,GAAG,IAAI,CACV,CAAA;AACL,CAAC,CAAA","sourcesContent":["const BASE_FORMAT = '%s [%c%s%c] [%c%s%c] '\nconst LEVEL_NAMES = [\n '', // OFF\n 'ERR',\n 'WRN',\n 'INF',\n 'DBG',\n 'VRB',\n]\nconst COLORS = [\n '', // OFF\n 'color: #7a5f9d',\n 'color: #8d7041',\n 'color: #396c9e',\n 'color: #437761',\n 'color: #7a5f9d',\n]\nconst TAG_COLORS = [\n 'color: #437761',\n 'color: #537a36',\n 'color: #8d7041',\n 'color: #396c9e',\n 'color: #7a5f9d',\n 'color: #7a5f9d',\n]\n\n/** @internal */\nexport const _defaultLoggingHandler = (\n color: number,\n level: number,\n tag: string,\n fmt: string,\n args: unknown[],\n): void => {\n // eslint-disable-next-line no-console\n console.log(\n BASE_FORMAT + fmt,\n new Date().toISOString(),\n COLORS[level],\n LEVEL_NAMES[level],\n '',\n TAG_COLORS[color],\n tag,\n '',\n ...args,\n )\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const _randomBytes: (size: number) => Uint8Array;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random.js","sourceRoot":"","sources":["../../../../src/utils/platform/random.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAEpC,MAAM,CAAC,MAAM,YAAY,GAAG,WAA2C,CAAA","sourcesContent":["// eslint-disable-next-line no-restricted-imports\nimport { randomBytes } from 'crypto'\n\nexport const _randomBytes = randomBytes as (size: number) => Uint8Array\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function _randomBytes(size: number): Uint8Array;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random.web.js","sourceRoot":"","sources":["../../../../src/utils/platform/random.web.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,YAAY,CAAC,IAAY;IACrC,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,CAAA;IAChC,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAA;IAE3B,OAAO,GAAG,CAAA;AACd,CAAC","sourcesContent":["export function _randomBytes(size: number): Uint8Array {\n const ret = new Uint8Array(size)\n crypto.getRandomValues(ret)\n\n return ret\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../../../src/utils/platform/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AAE9D,gBAAgB;AAChB,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,EAAE,CAAC,IAAI,YAAY,EAAE,CAAA","sourcesContent":["import { TcpTransport } from '../../network/transports/tcp.js'\n\n/** @internal */\nexport const _defaultTransportFactory = () => new TcpTransport()\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { WebSocketTransport } from '../../network/transports/websocket.js';
|
|
2
|
+
import { MtUnsupportedError } from '../../types/index.js';
|
|
3
|
+
/** @internal */
|
|
4
|
+
export const _defaultTransportFactory =
|
|
5
|
+
// if no websocket, throw an error i guess ¯\_(ツ)_/¯
|
|
6
|
+
// (user can still implement something on their own)
|
|
7
|
+
typeof WebSocket === 'undefined' ?
|
|
8
|
+
() => {
|
|
9
|
+
throw new MtUnsupportedError('Neither TCP nor WebSocket are available. Please pass a Transport factory explicitly');
|
|
10
|
+
} :
|
|
11
|
+
() => new WebSocketTransport();
|
|
12
|
+
//# sourceMappingURL=transport.web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.web.js","sourceRoot":"","sources":["../../../../src/utils/platform/transport.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAA;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAEzD,gBAAgB;AAChB,MAAM,CAAC,MAAM,wBAAwB;AACjC,oDAAoD;AACpD,oDAAoD;AACpD,OAAO,SAAS,KAAK,WAAW,CAAC,CAAC;IAC9B,GAAG,EAAE;QACD,MAAM,IAAI,kBAAkB,CACxB,qFAAqF,CACxF,CAAA;IACL,CAAC,CAAC,CAAC;IACH,GAAG,EAAE,CAAC,IAAI,kBAAkB,EAAE,CAAA","sourcesContent":["import { WebSocketTransport } from '../../network/transports/websocket.js'\nimport { MtUnsupportedError } from '../../types/index.js'\n\n/** @internal */\nexport const _defaultTransportFactory =\n // if no websocket, throw an error i guess ¯\\_(ツ)_/¯\n // (user can still implement something on their own)\n typeof WebSocket === 'undefined' ?\n () => {\n throw new MtUnsupportedError(\n 'Neither TCP nor WebSocket are available. Please pass a Transport factory explicitly',\n )\n } :\n () => new WebSocketTransport()\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Array that adds elements in sorted order.
|
|
3
|
+
*
|
|
4
|
+
* Comparator is always called like: comparator(itemFromSortedArray, yourItem)
|
|
5
|
+
*/
|
|
6
|
+
export declare class SortedArray<T> {
|
|
7
|
+
readonly comparator: (a: T, b: T) => number;
|
|
8
|
+
readonly raw: T[];
|
|
9
|
+
constructor(array: T[] | undefined, comparator: (a: T, b: T) => number);
|
|
10
|
+
get length(): number;
|
|
11
|
+
insert(item: T | T[]): number;
|
|
12
|
+
index(item: T, closest?: boolean): number;
|
|
13
|
+
remove(item: T): void;
|
|
14
|
+
includes(item: T): boolean;
|
|
15
|
+
find(item: T): T | null;
|
|
16
|
+
clear(): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Array that adds elements in sorted order.
|
|
3
|
+
*
|
|
4
|
+
* Comparator is always called like: comparator(itemFromSortedArray, yourItem)
|
|
5
|
+
*/
|
|
6
|
+
export class SortedArray {
|
|
7
|
+
constructor(array = [], comparator) {
|
|
8
|
+
this.comparator = comparator;
|
|
9
|
+
this.raw = array.sort(comparator);
|
|
10
|
+
this.comparator = comparator;
|
|
11
|
+
}
|
|
12
|
+
get length() {
|
|
13
|
+
return this.raw.length;
|
|
14
|
+
}
|
|
15
|
+
insert(item) {
|
|
16
|
+
if (Array.isArray(item)) {
|
|
17
|
+
let ind = -1;
|
|
18
|
+
item.forEach((it) => {
|
|
19
|
+
ind = this.insert(it);
|
|
20
|
+
});
|
|
21
|
+
return ind;
|
|
22
|
+
}
|
|
23
|
+
if (this.raw.length === 0) {
|
|
24
|
+
this.raw.push(item);
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
// find insert position
|
|
28
|
+
let lo = 0;
|
|
29
|
+
let hi = this.raw.length;
|
|
30
|
+
while (lo < hi) {
|
|
31
|
+
const mid = Math.floor((lo + hi) / 2);
|
|
32
|
+
if (this.comparator(this.raw[mid], item) > 0) {
|
|
33
|
+
hi = mid;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
lo = mid + 1;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
this.raw.splice(lo, 0, item);
|
|
40
|
+
return lo;
|
|
41
|
+
}
|
|
42
|
+
// closest: return the closest value (right-hand side)
|
|
43
|
+
// meaning that raw[idx - 1] <= item <= raw[idx]
|
|
44
|
+
index(item, closest = false) {
|
|
45
|
+
let lo = 0;
|
|
46
|
+
let hi = this.raw.length;
|
|
47
|
+
while (lo < hi) {
|
|
48
|
+
const mid = Math.floor((lo + hi) / 2);
|
|
49
|
+
const cmp = this.comparator(this.raw[mid], item);
|
|
50
|
+
if (cmp === 0) {
|
|
51
|
+
return mid;
|
|
52
|
+
}
|
|
53
|
+
if (cmp > 0) {
|
|
54
|
+
hi = mid;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
lo = mid + 1;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return closest ? lo : -1;
|
|
61
|
+
}
|
|
62
|
+
remove(item) {
|
|
63
|
+
const idx = this.index(item);
|
|
64
|
+
if (idx === -1)
|
|
65
|
+
return;
|
|
66
|
+
this.raw.splice(idx, 1);
|
|
67
|
+
}
|
|
68
|
+
includes(item) {
|
|
69
|
+
return this.index(item) !== -1;
|
|
70
|
+
}
|
|
71
|
+
find(item) {
|
|
72
|
+
const ind = this.index(item);
|
|
73
|
+
return ind === -1 ? null : this.raw[ind];
|
|
74
|
+
}
|
|
75
|
+
clear() {
|
|
76
|
+
this.raw.length = 0;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=sorted-array.js.map
|