@honeybbq/teamspeak-client 0.2.3 → 0.3.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/README.md +1 -0
- package/dist/address-BR-5unVo.cjs +2 -0
- package/dist/address-BR-5unVo.cjs.map +1 -0
- package/dist/address-BfmovVpp.js +65 -0
- package/dist/address-BfmovVpp.js.map +1 -0
- package/dist/address.d.ts +9 -0
- package/dist/address.d.ts.map +1 -0
- package/dist/address.test.d.ts +2 -0
- package/dist/address.test.d.ts.map +1 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.test.d.ts +2 -0
- package/dist/api.test.d.ts.map +1 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/command/index.cjs +1 -1
- package/dist/command/index.mjs +2 -2
- package/dist/{command-CTDmBXd_.js → command-BLe-C2L2.js} +2 -4
- package/dist/{command-CTDmBXd_.js.map → command-BLe-C2L2.js.map} +1 -1
- package/dist/command-DAK4pUBP.cjs +4 -0
- package/dist/{command-CUPNiKRl.cjs.map → command-DAK4pUBP.cjs.map} +1 -1
- package/dist/{crypt-handshake-D2Rsi2e3.cjs → crypt-handshake-CQkQreLx.cjs} +2 -2
- package/dist/{crypt-handshake-D2Rsi2e3.cjs.map → crypt-handshake-CQkQreLx.cjs.map} +1 -1
- package/dist/{crypt-handshake-DIj51kno.js → crypt-handshake-DziOY4Lq.js} +2 -2
- package/dist/{crypt-handshake-DIj51kno.js.map → crypt-handshake-DziOY4Lq.js.map} +1 -1
- package/dist/{crypt-init2-C2X9oK4i.js → crypt-init2-D70ha4LB.js} +6 -6
- package/dist/{crypt-init2-C2X9oK4i.js.map → crypt-init2-D70ha4LB.js.map} +1 -1
- package/dist/{crypt-init2-CazdFwqF.cjs → crypt-init2-DparLekm.cjs} +2 -2
- package/dist/{crypt-init2-CazdFwqF.cjs.map → crypt-init2-DparLekm.cjs.map} +1 -1
- package/dist/crypto/identity.d.ts.map +1 -1
- package/dist/crypto/index.cjs +1 -1
- package/dist/crypto/index.mjs +2 -2
- package/dist/{crypto-CwIMggQG.js → crypto-Bg02m4ZE.js} +7 -7
- package/dist/crypto-Bg02m4ZE.js.map +1 -0
- package/dist/crypto-CDlweUL3.cjs +2 -0
- package/dist/crypto-CDlweUL3.cjs.map +1 -0
- package/dist/discovery/index.cjs +1 -1
- package/dist/discovery/index.mjs +1 -1
- package/dist/discovery/resolver.d.ts.map +1 -1
- package/dist/{handler-BP38rMNl.js → handler-DI_abe9c.js} +153 -125
- package/dist/handler-DI_abe9c.js.map +1 -0
- package/dist/handler-DuwoO5RC.cjs +2 -0
- package/dist/handler-DuwoO5RC.cjs.map +1 -0
- package/dist/handshake/index.cjs +1 -1
- package/dist/handshake/index.mjs +2 -2
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +154 -140
- package/dist/index.mjs.map +1 -1
- package/dist/{parser-B6cGUByG.cjs → parser-CL33R9tr.cjs} +2 -2
- package/dist/{parser-B6cGUByG.cjs.map → parser-CL33R9tr.cjs.map} +1 -1
- package/dist/{parser-BPzO8py_.js → parser-DZMv3Jm-.js} +2 -2
- package/dist/{parser-BPzO8py_.js.map → parser-DZMv3Jm-.js.map} +1 -1
- package/dist/primitives-cNNAeFCo.cjs +2 -0
- package/dist/primitives-cNNAeFCo.cjs.map +1 -0
- package/dist/primitives-xIr6Tjk4.js +1457 -0
- package/dist/primitives-xIr6Tjk4.js.map +1 -0
- package/dist/resolver-6B8dI9gr.js +141 -0
- package/dist/resolver-6B8dI9gr.js.map +1 -0
- package/dist/resolver-DCcmyWSK.cjs +4 -0
- package/dist/resolver-DCcmyWSK.cjs.map +1 -0
- package/dist/transport/handler.d.ts +2 -0
- package/dist/transport/handler.d.ts.map +1 -1
- package/dist/transport/index.cjs +1 -1
- package/dist/transport/index.mjs +1 -1
- package/dist/transport/whisper.test.d.ts +2 -0
- package/dist/transport/whisper.test.d.ts.map +1 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/dist/command-CUPNiKRl.cjs +0 -4
- package/dist/crypto-CwIMggQG.js.map +0 -1
- package/dist/crypto-IbzNNTgO.cjs +0 -2
- package/dist/crypto-IbzNNTgO.cjs.map +0 -1
- package/dist/handler-BJdwhtkp.cjs +0 -2
- package/dist/handler-BJdwhtkp.cjs.map +0 -1
- package/dist/handler-BP38rMNl.js.map +0 -1
- package/dist/primitives-Bt-L4BZa.js +0 -1483
- package/dist/primitives-Bt-L4BZa.js.map +0 -1
- package/dist/primitives-ClIhDdNZ.cjs +0 -2
- package/dist/primitives-ClIhDdNZ.cjs.map +0 -1
- package/dist/resolver-B7jho9CP.cjs +0 -4
- package/dist/resolver-B7jho9CP.cjs.map +0 -1
- package/dist/resolver-BDCF2KbM.js +0 -162
- package/dist/resolver-BDCF2KbM.js.map +0 -1
- package/dist/types-ANvuLFWH.cjs +0 -2
- package/dist/types-ANvuLFWH.cjs.map +0 -1
- package/dist/types-Xm1vrW4s.js +0 -18
- package/dist/types-Xm1vrW4s.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto-Bg02m4ZE.js","names":[],"sources":["../src/crypto/eax.ts","../src/crypto/crypt.ts"],"sourcesContent":["import { createCipheriv, timingSafeEqual } from \"node:crypto\";\nimport { EAXTagMismatchError } from \"../errors.js\";\n\nconst EAX_TAG_SIZE = 8;\nconst EAX_BLOCK_SIZE = 16;\n\n/**\n * AES-EAX AEAD implementation for TS3 (64-bit tag, AES-128).\n * Uses AES-CMAC for authentication and AES-CTR for encryption.\n */\nexport class EAX {\n readonly #key: Uint8Array;\n\n constructor(key: Uint8Array) {\n if (key.length !== 16) throw new Error(\"EAX requires a 16-byte key\");\n this.#key = key;\n }\n\n encrypt(\n nonce: Uint8Array,\n header: Uint8Array,\n plaintext: Uint8Array,\n ): [ciphertext: Uint8Array, tag: Uint8Array] {\n const nStar = this.#cmac(0, nonce);\n const hStar = this.#cmac(1, header);\n\n const ciphertext = aesCtr(this.#key, nStar, plaintext);\n\n const cStar = this.#cmac(2, ciphertext);\n\n const tag = new Uint8Array(EAX_TAG_SIZE);\n for (let i = 0; i < EAX_TAG_SIZE; i++) {\n tag[i] = nStar[i]! ^ hStar[i]! ^ cStar[i]!;\n }\n\n return [ciphertext, tag];\n }\n\n decrypt(\n nonce: Uint8Array,\n header: Uint8Array,\n ciphertext: Uint8Array,\n tag: Uint8Array,\n ): Uint8Array {\n const nStar = this.#cmac(0, nonce);\n const hStar = this.#cmac(1, header);\n const cStar = this.#cmac(2, ciphertext);\n\n const expected = new Uint8Array(EAX_TAG_SIZE);\n for (let i = 0; i < EAX_TAG_SIZE; i++) {\n expected[i] = nStar[i]! ^ hStar[i]! ^ cStar[i]!;\n }\n\n if (!timingSafeEqual(Buffer.from(expected), Buffer.from(tag.slice(0, EAX_TAG_SIZE)))) {\n throw new EAXTagMismatchError();\n }\n\n return aesCtr(this.#key, nStar, ciphertext);\n }\n\n /**\n * AES-CMAC per RFC 4493:\n * input = [0…0 tag] ++ data (one block prefix)\n */\n #cmac(tagByte: number, data: Uint8Array): Uint8Array {\n const input = new Uint8Array(EAX_BLOCK_SIZE + data.length);\n // first block: zeros then tag byte at the last position\n input[EAX_BLOCK_SIZE - 1] = tagByte;\n input.set(data, EAX_BLOCK_SIZE);\n\n return aesCmac(this.#key, input);\n }\n}\n\n// ---- AES-CTR ----------------------------------------------------------------\n\nfunction aesCtr(key: Uint8Array, iv: Uint8Array, data: Uint8Array): Uint8Array {\n const cipher = createCipheriv(\"aes-128-ctr\", Buffer.from(key), Buffer.from(iv));\n return Buffer.concat([cipher.update(Buffer.from(data)), cipher.final()]);\n}\n\n// ---- AES-CMAC (RFC 4493) ----------------------------------------------------\n\nfunction aesEcb(key: Uint8Array, block: Uint8Array): Uint8Array {\n // Node.js does not expose ECB directly; simulate via CTR with zero IV and\n // a zero-input (CTR of 0-block XOR with input = ECB)\n const cipher = createCipheriv(\"aes-128-ecb\", Buffer.from(key), null);\n cipher.setAutoPadding(false);\n return Buffer.concat([cipher.update(Buffer.from(block)), cipher.final()]);\n}\n\nfunction xorBlock(a: Uint8Array, b: Uint8Array): Uint8Array {\n const out = new Uint8Array(EAX_BLOCK_SIZE);\n for (let i = 0; i < EAX_BLOCK_SIZE; i++) out[i] = a[i]! ^ b[i]!;\n return out;\n}\n\nfunction shiftLeft1(b: Uint8Array): Uint8Array {\n const out = new Uint8Array(EAX_BLOCK_SIZE);\n let carry = 0;\n for (let i = EAX_BLOCK_SIZE - 1; i >= 0; i--) {\n const shifted = ((b[i]! << 1) | carry) & 0xff;\n carry = b[i]! >> 7;\n out[i] = shifted;\n }\n return out;\n}\n\nconst RB = new Uint8Array(EAX_BLOCK_SIZE);\nRB[EAX_BLOCK_SIZE - 1] = 0x87;\n\nfunction generateSubkeys(key: Uint8Array): [Uint8Array, Uint8Array] {\n const zero = new Uint8Array(EAX_BLOCK_SIZE);\n const L = aesEcb(key, zero);\n\n let K1 = shiftLeft1(L);\n if ((L[0]! & 0x80) !== 0) K1 = xorBlock(K1, RB);\n\n let K2 = shiftLeft1(K1);\n if ((K1[0]! & 0x80) !== 0) K2 = xorBlock(K2, RB);\n\n return [K1, K2];\n}\n\nexport function aesCmac(key: Uint8Array, message: Uint8Array): Uint8Array {\n const [K1, K2] = generateSubkeys(key);\n\n const n = Math.max(1, Math.ceil(message.length / EAX_BLOCK_SIZE));\n const lastBlockComplete = message.length > 0 && message.length % EAX_BLOCK_SIZE === 0;\n\n let X: Uint8Array = new Uint8Array(EAX_BLOCK_SIZE);\n\n for (let i = 0; i < n - 1; i++) {\n const block = message.slice(i * EAX_BLOCK_SIZE, (i + 1) * EAX_BLOCK_SIZE);\n X = Uint8Array.from(aesEcb(key, xorBlock(X, block)));\n }\n\n const lastBlock = new Uint8Array(EAX_BLOCK_SIZE);\n const lastStart = (n - 1) * EAX_BLOCK_SIZE;\n const lastSlice = message.slice(lastStart);\n lastBlock.set(lastSlice);\n\n let Mn: Uint8Array;\n if (lastBlockComplete) {\n Mn = xorBlock(lastBlock, K1);\n } else {\n if (lastSlice.length < EAX_BLOCK_SIZE) lastBlock[lastSlice.length] = 0x80;\n Mn = xorBlock(lastBlock, K2);\n }\n\n return Uint8Array.from(aesEcb(key, xorBlock(X, Mn)));\n}\n","import { createHash, createECDH } from \"node:crypto\";\nimport { FakeSignatureMismatchError } from \"../errors.js\";\nimport type { Identity } from \"./identity.js\";\nimport { importPublicKey } from \"./identity.js\";\nimport { EAX } from \"./eax.js\";\n\nconst FAKE_SIGNATURE_SIZE = 8;\nconst IV_ALPHA_SIZE = 10;\nconst INIT1_PACKET_TYPE = 8;\nconst PACKET_TYPE_MASK = 0x0f;\n\nconst INIT1_MAC = Buffer.from(\"TS3INIT1\");\n\nexport interface KeyNonce {\n key: Uint8Array;\n nonce: Uint8Array;\n gen: number;\n}\n\n/** Precomputed dummy key/nonce matching the TS3 client pre-crypto placeholder. */\nconst DUMMY_KEY = Buffer.from(\"c:\\\\windows\\\\syste\");\nconst DUMMY_NONCE = Buffer.from(\"m\\\\firewall32.cpl\");\n\nexport class Crypt {\n readonly identity: Identity;\n\n ivStruct: Uint8Array = new Uint8Array(0);\n fakeSignature: Uint8Array = new Uint8Array(FAKE_SIGNATURE_SIZE);\n alphaTmp: Uint8Array = new Uint8Array(0);\n cryptoInitComplete = false;\n\n readonly #cachedKeys = new Map<bigint, KeyNonce>();\n\n constructor(identity: Identity) {\n this.identity = identity;\n }\n\n solveRsaChallenge(data: Uint8Array, offset: number, level: number): Uint8Array {\n if (level < 0 || level > 1_000_000) {\n throw new Error(\"RSA challenge level out of range\");\n }\n\n const xBytes = data.slice(offset, offset + 64);\n const nBytes = data.slice(offset + 64, offset + 128);\n\n let y = bytesToBigInt(xBytes);\n const n = bytesToBigInt(nBytes);\n\n for (let i = 0; i < level; i++) {\n y = (y * y) % n;\n }\n\n return bigIntToBytes(y, 64);\n }\n\n initCrypto(alpha: string, beta: string, omega: string): void {\n const alphaBytes = Buffer.from(alpha, \"base64\");\n const betaBytes = Buffer.from(beta, \"base64\");\n const omegaBytes = Buffer.from(omega, \"base64\");\n\n const serverPubKey = importPublicKey(omegaBytes);\n const sharedSecret = this.#getSharedSecret(serverPubKey);\n\n this.setSharedSecret(alphaBytes, betaBytes, sharedSecret);\n }\n\n setSharedSecret(alpha: Uint8Array, beta: Uint8Array, sharedKey: Uint8Array): void {\n this.ivStruct = new Uint8Array(IV_ALPHA_SIZE + beta.length);\n for (let i = 0; i < IV_ALPHA_SIZE; i++) {\n const a = sharedKey[i];\n const b = alpha[i];\n this.ivStruct[i] = ((a !== undefined ? a : 0) ^ (b !== undefined ? b : 0)) & 0xff;\n }\n for (let i = 0; i < beta.length; i++) {\n const a = sharedKey[IV_ALPHA_SIZE + i];\n const b = beta[i];\n this.ivStruct[IV_ALPHA_SIZE + i] =\n ((a !== undefined ? a : 0) ^ (b !== undefined ? b : 0)) & 0xff;\n }\n\n const digest = createHash(\"sha1\").update(this.ivStruct).digest();\n this.fakeSignature = new Uint8Array(digest.buffer, digest.byteOffset, FAKE_SIGNATURE_SIZE);\n this.cryptoInitComplete = true;\n }\n\n getKeyNonce(\n fromServer: boolean,\n packetID: number,\n generationID: number,\n packetType: number,\n dummy: boolean,\n ): [key: Uint8Array, nonce: Uint8Array] {\n if (dummy) {\n return [Uint8Array.from(DUMMY_KEY), Uint8Array.from(DUMMY_NONCE)];\n }\n\n const cacheKey = makeCacheKey(fromServer, packetType, generationID);\n let kn = this.#cachedKeys.get(cacheKey);\n\n if (kn === undefined) {\n const tmpToHash = new Uint8Array(6 + this.ivStruct.length);\n tmpToHash[0] = fromServer ? 0x30 : 0x31;\n tmpToHash[1] = packetType & PACKET_TYPE_MASK;\n new DataView(tmpToHash.buffer).setUint32(2, generationID, false);\n tmpToHash.set(this.ivStruct, 6);\n\n const hash = createHash(\"sha256\").update(tmpToHash).digest();\n kn = {\n key: Uint8Array.from(hash.slice(0, 16)),\n nonce: Uint8Array.from(hash.slice(16, 32)),\n gen: generationID,\n };\n this.#cachedKeys.set(cacheKey, kn);\n }\n\n const key = Uint8Array.from(kn.key);\n key[0] = (key[0] !== undefined ? key[0] : 0) ^ ((packetID >> 8) & 0xff);\n key[1] = (key[1] !== undefined ? key[1] : 0) ^ (packetID & 0xff);\n\n return [key, kn.nonce];\n }\n\n encrypt(\n packetType: number,\n packetID: number,\n generationID: number,\n header: Uint8Array,\n plaintext: Uint8Array,\n dummy: boolean,\n unencrypted: boolean,\n ): [ciphertext: Uint8Array, mac: Uint8Array] {\n if (packetType === INIT1_PACKET_TYPE) {\n return [plaintext, INIT1_MAC];\n }\n if (unencrypted) {\n return [plaintext, this.fakeSignature];\n }\n\n const [key, nonce] = this.getKeyNonce(false, packetID, generationID, packetType, dummy);\n const eax = new EAX(key);\n return eax.encrypt(nonce, header, plaintext);\n }\n\n decrypt(\n packetType: number,\n packetID: number,\n generationID: number,\n header: Uint8Array,\n ciphertext: Uint8Array,\n tag: Uint8Array,\n dummy: boolean,\n unencrypted: boolean,\n ): Uint8Array {\n if (packetType === INIT1_PACKET_TYPE) {\n return ciphertext;\n }\n if (unencrypted) {\n const fsSub = tag.slice(0, FAKE_SIGNATURE_SIZE);\n if (!Buffer.from(fsSub).equals(Buffer.from(this.fakeSignature))) {\n throw new FakeSignatureMismatchError();\n }\n return ciphertext;\n }\n\n const [key, nonce] = this.getKeyNonce(true, packetID, generationID, packetType, dummy);\n const eax = new EAX(key);\n return eax.decrypt(nonce, header, ciphertext, tag);\n }\n\n #getSharedSecret(serverPubKey: import(\"node:crypto\").KeyObject): Uint8Array {\n const privJwk = this.identity.privateKey.export({ format: \"jwk\" }) as {\n d: string;\n };\n const pubJwk = serverPubKey.export({ format: \"jwk\" }) as {\n x: string;\n y: string;\n };\n\n const ecdh = createECDH(\"prime256v1\");\n const dBytes = Buffer.from(privJwk.d, \"base64url\");\n ecdh.setPrivateKey(dBytes);\n\n const xBytes = base64UrlToBytes(pubJwk.x, 32);\n const yBytes = base64UrlToBytes(pubJwk.y, 32);\n const uncompressed = Buffer.alloc(65);\n uncompressed[0] = 0x04;\n xBytes.copy(uncompressed, 1);\n yBytes.copy(uncompressed, 33);\n\n const rawSecret = ecdh.computeSecret(uncompressed);\n return createHash(\"sha1\").update(rawSecret).digest();\n }\n}\n\n// ---- Helpers ----------------------------------------------------------------\n\nfunction makeCacheKey(fromServer: boolean, packetType: number, generationID: number): bigint {\n let key = 0n;\n if (fromServer) key |= 1n << 40n;\n key |= BigInt(packetType & PACKET_TYPE_MASK) << 32n;\n key |= BigInt(generationID);\n return key;\n}\n\nfunction bytesToBigInt(bytes: Uint8Array): bigint {\n let result = 0n;\n for (const b of bytes) result = (result << 8n) | BigInt(b);\n return result;\n}\n\nfunction bigIntToBytes(value: bigint, size: number): Uint8Array {\n const result = new Uint8Array(size);\n let v = value;\n for (let i = size - 1; i >= 0; i--) {\n result[i] = Number(v & 0xffn);\n v >>= 8n;\n }\n return result;\n}\n\nfunction base64UrlToBytes(b64url: string, size: number): Buffer {\n const buf = Buffer.from(b64url, \"base64url\");\n if (buf.length === size) return buf;\n const padded = Buffer.alloc(size);\n buf.copy(padded, size - buf.length);\n return padded;\n}\n"],"mappings":";;;AAGA,IAAM,IAAe,GACf,IAAiB,IAMV,IAAb,MAAiB;CACf;CAEA,YAAY,GAAiB;EAC3B,IAAI,EAAI,WAAW,IAAI,MAAU,MAAM,4BAA4B;EACnE,KAAK,KAAO;CACd;CAEA,QACE,GACA,GACA,GAC2C;EAC3C,IAAM,IAAQ,KAAK,GAAM,GAAG,CAAK,GAC3B,IAAQ,KAAK,GAAM,GAAG,CAAM,GAE5B,IAAa,EAAO,KAAK,IAAM,GAAO,CAAS,GAE/C,IAAQ,KAAK,GAAM,GAAG,CAAU,GAEhC,IAAM,IAAI,WAAW,CAAY;EACvC,KAAK,IAAI,IAAI,GAAG,IAAI,GAAc,KAChC,EAAI,KAAK,EAAM,KAAM,EAAM,KAAM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GAAG,EAAE,GACtC,IAAe,OAAO,MAAM,EAAE;EAGpC,AAFA,EAAa,KAAK,GAClB,EAAO,KAAK,GAAc,CAAC,GAC3B,EAAO,KAAK,GAAc,EAAE;EAE5B,IAAM,IAAY,EAAK,cAAc,CAAY;EACjD,OAAO,EAAW,MAAM,CAAC,CAAC,OAAO,CAAS,CAAC,CAAC,OAAO;CACrD;AACF;AAIA,SAAS,EAAa,GAAqB,GAAoB,GAA8B;CAC3F,IAAI,IAAM;CAIV,OAHI,MAAY,KAAO,MAAM,MAC7B,KAAO,OAAO,IAAa,CAAgB,KAAK,KAChD,KAAO,OAAO,CAAY,GACnB;AACT;AAEA,SAAS,EAAc,GAA2B;CAChD,IAAI,IAAS;CACb,KAAK,IAAM,KAAK,GAAO,IAAU,KAAU,KAAM,OAAO,CAAC;CACzD,OAAO;AACT;AAEA,SAAS,EAAc,GAAe,GAA0B;CAC9D,IAAM,IAAS,IAAI,WAAW,CAAI,GAC9B,IAAI;CACR,KAAK,IAAI,IAAI,IAAO,GAAG,KAAK,GAAG,KAE7B,AADA,EAAO,KAAK,OAAO,IAAI,IAAK,GAC5B,MAAM;CAER,OAAO;AACT;AAEA,SAAS,EAAiB,GAAgB,GAAsB;CAC9D,IAAM,IAAM,OAAO,KAAK,GAAQ,WAAW;CAC3C,IAAI,EAAI,WAAW,GAAM,OAAO;CAChC,IAAM,IAAS,OAAO,MAAM,CAAI;CAEhC,OADA,EAAI,KAAK,GAAQ,IAAO,EAAI,MAAM,GAC3B;AACT"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./primitives-cNNAeFCo.cjs");let t=require("node:crypto");var n=8,r=16,i=class{#e;constructor(e){if(e.length!==16)throw Error(`EAX requires a 16-byte key`);this.#e=e}encrypt(e,t,r){let i=this.#t(0,e),o=this.#t(1,t),s=a(this.#e,i,r),c=this.#t(2,s),l=new Uint8Array(n);for(let e=0;e<n;e++)l[e]=i[e]^o[e]^c[e];return[s,l]}decrypt(r,i,o,s){let c=this.#t(0,r),l=this.#t(1,i),u=this.#t(2,o),d=new Uint8Array(n);for(let e=0;e<n;e++)d[e]=c[e]^l[e]^u[e];if(!(0,t.timingSafeEqual)(Buffer.from(d),Buffer.from(s.slice(0,n))))throw new e.v;return a(this.#e,c,o)}#t(e,t){let n=new Uint8Array(r+t.length);return n[15]=e,n.set(t,r),d(this.#e,n)}};function a(e,n,r){let i=(0,t.createCipheriv)(`aes-128-ctr`,Buffer.from(e),Buffer.from(n));return Buffer.concat([i.update(Buffer.from(r)),i.final()])}function o(e,n){let r=(0,t.createCipheriv)(`aes-128-ecb`,Buffer.from(e),null);return r.setAutoPadding(!1),Buffer.concat([r.update(Buffer.from(n)),r.final()])}function s(e,t){let n=new Uint8Array(r);for(let i=0;i<r;i++)n[i]=e[i]^t[i];return n}function c(e){let t=new Uint8Array(r),n=0;for(let r=15;r>=0;r--){let i=(e[r]<<1|n)&255;n=e[r]>>7,t[r]=i}return t}var l=new Uint8Array(r);l[15]=135;function u(e){let t=o(e,new Uint8Array(r)),n=c(t);t[0]&128&&(n=s(n,l));let i=c(n);return n[0]&128&&(i=s(i,l)),[n,i]}function d(e,t){let[n,i]=u(e),a=Math.max(1,Math.ceil(t.length/r)),c=t.length>0&&t.length%r===0,l=new Uint8Array(r);for(let n=0;n<a-1;n++){let i=t.slice(n*r,(n+1)*r);l=Uint8Array.from(o(e,s(l,i)))}let d=new Uint8Array(r),f=(a-1)*r,p=t.slice(f);d.set(p);let m;return c?m=s(d,n):(p.length<r&&(d[p.length]=128),m=s(d,i)),Uint8Array.from(o(e,s(l,m)))}var f=8,p=10,m=8,h=15,g=Buffer.from(`TS3INIT1`),_=Buffer.from(`c:\\windows\\syste`),v=Buffer.from(`m\\firewall32.cpl`),y=class{identity;ivStruct=new Uint8Array;fakeSignature=new Uint8Array(f);alphaTmp=new Uint8Array;cryptoInitComplete=!1;#e=new Map;constructor(e){this.identity=e}solveRsaChallenge(e,t,n){if(n<0||n>1e6)throw Error(`RSA challenge level out of range`);let r=e.slice(t,t+64),i=e.slice(t+64,t+128),a=x(r),o=x(i);for(let e=0;e<n;e++)a=a*a%o;return S(a,64)}initCrypto(t,n,r){let i=Buffer.from(t,`base64`),a=Buffer.from(n,`base64`),o=Buffer.from(r,`base64`),s=e.m(o),c=this.#t(s);this.setSharedSecret(i,a,c)}setSharedSecret(e,n,r){this.ivStruct=new Uint8Array(p+n.length);for(let t=0;t<p;t++){let n=r[t],i=e[t];this.ivStruct[t]=((n===void 0?0:n)^(i===void 0?0:i))&255}for(let e=0;e<n.length;e++){let t=r[p+e],i=n[e];this.ivStruct[p+e]=((t===void 0?0:t)^(i===void 0?0:i))&255}let i=(0,t.createHash)(`sha1`).update(this.ivStruct).digest();this.fakeSignature=new Uint8Array(i.buffer,i.byteOffset,f),this.cryptoInitComplete=!0}getKeyNonce(e,n,r,i,a){if(a)return[Uint8Array.from(_),Uint8Array.from(v)];let o=b(e,i,r),s=this.#e.get(o);if(s===void 0){let n=new Uint8Array(6+this.ivStruct.length);n[0]=e?48:49,n[1]=i&h,new DataView(n.buffer).setUint32(2,r,!1),n.set(this.ivStruct,6);let a=(0,t.createHash)(`sha256`).update(n).digest();s={key:Uint8Array.from(a.slice(0,16)),nonce:Uint8Array.from(a.slice(16,32)),gen:r},this.#e.set(o,s)}let c=Uint8Array.from(s.key);return c[0]=(c[0]===void 0?0:c[0])^n>>8&255,c[1]=(c[1]===void 0?0:c[1])^n&255,[c,s.nonce]}encrypt(e,t,n,r,a,o,s){if(e===m)return[a,g];if(s)return[a,this.fakeSignature];let[c,l]=this.getKeyNonce(!1,t,n,e,o);return new i(c).encrypt(l,r,a)}decrypt(t,n,r,a,o,s,c,l){if(t===m)return o;if(l){let t=s.slice(0,f);if(!Buffer.from(t).equals(Buffer.from(this.fakeSignature)))throw new e.y;return o}let[u,d]=this.getKeyNonce(!0,n,r,t,c);return new i(u).decrypt(d,a,o,s)}#t(e){let n=this.identity.privateKey.export({format:`jwk`}),r=e.export({format:`jwk`}),i=(0,t.createECDH)(`prime256v1`),a=Buffer.from(n.d,`base64url`);i.setPrivateKey(a);let o=C(r.x,32),s=C(r.y,32),c=Buffer.alloc(65);c[0]=4,o.copy(c,1),s.copy(c,33);let l=i.computeSecret(c);return(0,t.createHash)(`sha1`).update(l).digest()}};function b(e,t,n){let r=0n;return e&&(r|=1n<<40n),r|=BigInt(t&h)<<32n,r|=BigInt(n),r}function x(e){let t=0n;for(let n of e)t=t<<8n|BigInt(n);return t}function S(e,t){let n=new Uint8Array(t),r=e;for(let e=t-1;e>=0;e--)n[e]=Number(r&255n),r>>=8n;return n}function C(e,t){let n=Buffer.from(e,`base64url`);if(n.length===t)return n;let r=Buffer.alloc(t);return n.copy(r,t-n.length),r}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return y}});
|
|
2
|
+
//# sourceMappingURL=crypto-CDlweUL3.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto-CDlweUL3.cjs","names":[],"sources":["../src/crypto/eax.ts","../src/crypto/crypt.ts"],"sourcesContent":["import { createCipheriv, timingSafeEqual } from \"node:crypto\";\nimport { EAXTagMismatchError } from \"../errors.js\";\n\nconst EAX_TAG_SIZE = 8;\nconst EAX_BLOCK_SIZE = 16;\n\n/**\n * AES-EAX AEAD implementation for TS3 (64-bit tag, AES-128).\n * Uses AES-CMAC for authentication and AES-CTR for encryption.\n */\nexport class EAX {\n readonly #key: Uint8Array;\n\n constructor(key: Uint8Array) {\n if (key.length !== 16) throw new Error(\"EAX requires a 16-byte key\");\n this.#key = key;\n }\n\n encrypt(\n nonce: Uint8Array,\n header: Uint8Array,\n plaintext: Uint8Array,\n ): [ciphertext: Uint8Array, tag: Uint8Array] {\n const nStar = this.#cmac(0, nonce);\n const hStar = this.#cmac(1, header);\n\n const ciphertext = aesCtr(this.#key, nStar, plaintext);\n\n const cStar = this.#cmac(2, ciphertext);\n\n const tag = new Uint8Array(EAX_TAG_SIZE);\n for (let i = 0; i < EAX_TAG_SIZE; i++) {\n tag[i] = nStar[i]! ^ hStar[i]! ^ cStar[i]!;\n }\n\n return [ciphertext, tag];\n }\n\n decrypt(\n nonce: Uint8Array,\n header: Uint8Array,\n ciphertext: Uint8Array,\n tag: Uint8Array,\n ): Uint8Array {\n const nStar = this.#cmac(0, nonce);\n const hStar = this.#cmac(1, header);\n const cStar = this.#cmac(2, ciphertext);\n\n const expected = new Uint8Array(EAX_TAG_SIZE);\n for (let i = 0; i < EAX_TAG_SIZE; i++) {\n expected[i] = nStar[i]! ^ hStar[i]! ^ cStar[i]!;\n }\n\n if (!timingSafeEqual(Buffer.from(expected), Buffer.from(tag.slice(0, EAX_TAG_SIZE)))) {\n throw new EAXTagMismatchError();\n }\n\n return aesCtr(this.#key, nStar, ciphertext);\n }\n\n /**\n * AES-CMAC per RFC 4493:\n * input = [0…0 tag] ++ data (one block prefix)\n */\n #cmac(tagByte: number, data: Uint8Array): Uint8Array {\n const input = new Uint8Array(EAX_BLOCK_SIZE + data.length);\n // first block: zeros then tag byte at the last position\n input[EAX_BLOCK_SIZE - 1] = tagByte;\n input.set(data, EAX_BLOCK_SIZE);\n\n return aesCmac(this.#key, input);\n }\n}\n\n// ---- AES-CTR ----------------------------------------------------------------\n\nfunction aesCtr(key: Uint8Array, iv: Uint8Array, data: Uint8Array): Uint8Array {\n const cipher = createCipheriv(\"aes-128-ctr\", Buffer.from(key), Buffer.from(iv));\n return Buffer.concat([cipher.update(Buffer.from(data)), cipher.final()]);\n}\n\n// ---- AES-CMAC (RFC 4493) ----------------------------------------------------\n\nfunction aesEcb(key: Uint8Array, block: Uint8Array): Uint8Array {\n // Node.js does not expose ECB directly; simulate via CTR with zero IV and\n // a zero-input (CTR of 0-block XOR with input = ECB)\n const cipher = createCipheriv(\"aes-128-ecb\", Buffer.from(key), null);\n cipher.setAutoPadding(false);\n return Buffer.concat([cipher.update(Buffer.from(block)), cipher.final()]);\n}\n\nfunction xorBlock(a: Uint8Array, b: Uint8Array): Uint8Array {\n const out = new Uint8Array(EAX_BLOCK_SIZE);\n for (let i = 0; i < EAX_BLOCK_SIZE; i++) out[i] = a[i]! ^ b[i]!;\n return out;\n}\n\nfunction shiftLeft1(b: Uint8Array): Uint8Array {\n const out = new Uint8Array(EAX_BLOCK_SIZE);\n let carry = 0;\n for (let i = EAX_BLOCK_SIZE - 1; i >= 0; i--) {\n const shifted = ((b[i]! << 1) | carry) & 0xff;\n carry = b[i]! >> 7;\n out[i] = shifted;\n }\n return out;\n}\n\nconst RB = new Uint8Array(EAX_BLOCK_SIZE);\nRB[EAX_BLOCK_SIZE - 1] = 0x87;\n\nfunction generateSubkeys(key: Uint8Array): [Uint8Array, Uint8Array] {\n const zero = new Uint8Array(EAX_BLOCK_SIZE);\n const L = aesEcb(key, zero);\n\n let K1 = shiftLeft1(L);\n if ((L[0]! & 0x80) !== 0) K1 = xorBlock(K1, RB);\n\n let K2 = shiftLeft1(K1);\n if ((K1[0]! & 0x80) !== 0) K2 = xorBlock(K2, RB);\n\n return [K1, K2];\n}\n\nexport function aesCmac(key: Uint8Array, message: Uint8Array): Uint8Array {\n const [K1, K2] = generateSubkeys(key);\n\n const n = Math.max(1, Math.ceil(message.length / EAX_BLOCK_SIZE));\n const lastBlockComplete = message.length > 0 && message.length % EAX_BLOCK_SIZE === 0;\n\n let X: Uint8Array = new Uint8Array(EAX_BLOCK_SIZE);\n\n for (let i = 0; i < n - 1; i++) {\n const block = message.slice(i * EAX_BLOCK_SIZE, (i + 1) * EAX_BLOCK_SIZE);\n X = Uint8Array.from(aesEcb(key, xorBlock(X, block)));\n }\n\n const lastBlock = new Uint8Array(EAX_BLOCK_SIZE);\n const lastStart = (n - 1) * EAX_BLOCK_SIZE;\n const lastSlice = message.slice(lastStart);\n lastBlock.set(lastSlice);\n\n let Mn: Uint8Array;\n if (lastBlockComplete) {\n Mn = xorBlock(lastBlock, K1);\n } else {\n if (lastSlice.length < EAX_BLOCK_SIZE) lastBlock[lastSlice.length] = 0x80;\n Mn = xorBlock(lastBlock, K2);\n }\n\n return Uint8Array.from(aesEcb(key, xorBlock(X, Mn)));\n}\n","import { createHash, createECDH } from \"node:crypto\";\nimport { FakeSignatureMismatchError } from \"../errors.js\";\nimport type { Identity } from \"./identity.js\";\nimport { importPublicKey } from \"./identity.js\";\nimport { EAX } from \"./eax.js\";\n\nconst FAKE_SIGNATURE_SIZE = 8;\nconst IV_ALPHA_SIZE = 10;\nconst INIT1_PACKET_TYPE = 8;\nconst PACKET_TYPE_MASK = 0x0f;\n\nconst INIT1_MAC = Buffer.from(\"TS3INIT1\");\n\nexport interface KeyNonce {\n key: Uint8Array;\n nonce: Uint8Array;\n gen: number;\n}\n\n/** Precomputed dummy key/nonce matching the TS3 client pre-crypto placeholder. */\nconst DUMMY_KEY = Buffer.from(\"c:\\\\windows\\\\syste\");\nconst DUMMY_NONCE = Buffer.from(\"m\\\\firewall32.cpl\");\n\nexport class Crypt {\n readonly identity: Identity;\n\n ivStruct: Uint8Array = new Uint8Array(0);\n fakeSignature: Uint8Array = new Uint8Array(FAKE_SIGNATURE_SIZE);\n alphaTmp: Uint8Array = new Uint8Array(0);\n cryptoInitComplete = false;\n\n readonly #cachedKeys = new Map<bigint, KeyNonce>();\n\n constructor(identity: Identity) {\n this.identity = identity;\n }\n\n solveRsaChallenge(data: Uint8Array, offset: number, level: number): Uint8Array {\n if (level < 0 || level > 1_000_000) {\n throw new Error(\"RSA challenge level out of range\");\n }\n\n const xBytes = data.slice(offset, offset + 64);\n const nBytes = data.slice(offset + 64, offset + 128);\n\n let y = bytesToBigInt(xBytes);\n const n = bytesToBigInt(nBytes);\n\n for (let i = 0; i < level; i++) {\n y = (y * y) % n;\n }\n\n return bigIntToBytes(y, 64);\n }\n\n initCrypto(alpha: string, beta: string, omega: string): void {\n const alphaBytes = Buffer.from(alpha, \"base64\");\n const betaBytes = Buffer.from(beta, \"base64\");\n const omegaBytes = Buffer.from(omega, \"base64\");\n\n const serverPubKey = importPublicKey(omegaBytes);\n const sharedSecret = this.#getSharedSecret(serverPubKey);\n\n this.setSharedSecret(alphaBytes, betaBytes, sharedSecret);\n }\n\n setSharedSecret(alpha: Uint8Array, beta: Uint8Array, sharedKey: Uint8Array): void {\n this.ivStruct = new Uint8Array(IV_ALPHA_SIZE + beta.length);\n for (let i = 0; i < IV_ALPHA_SIZE; i++) {\n const a = sharedKey[i];\n const b = alpha[i];\n this.ivStruct[i] = ((a !== undefined ? a : 0) ^ (b !== undefined ? b : 0)) & 0xff;\n }\n for (let i = 0; i < beta.length; i++) {\n const a = sharedKey[IV_ALPHA_SIZE + i];\n const b = beta[i];\n this.ivStruct[IV_ALPHA_SIZE + i] =\n ((a !== undefined ? a : 0) ^ (b !== undefined ? b : 0)) & 0xff;\n }\n\n const digest = createHash(\"sha1\").update(this.ivStruct).digest();\n this.fakeSignature = new Uint8Array(digest.buffer, digest.byteOffset, FAKE_SIGNATURE_SIZE);\n this.cryptoInitComplete = true;\n }\n\n getKeyNonce(\n fromServer: boolean,\n packetID: number,\n generationID: number,\n packetType: number,\n dummy: boolean,\n ): [key: Uint8Array, nonce: Uint8Array] {\n if (dummy) {\n return [Uint8Array.from(DUMMY_KEY), Uint8Array.from(DUMMY_NONCE)];\n }\n\n const cacheKey = makeCacheKey(fromServer, packetType, generationID);\n let kn = this.#cachedKeys.get(cacheKey);\n\n if (kn === undefined) {\n const tmpToHash = new Uint8Array(6 + this.ivStruct.length);\n tmpToHash[0] = fromServer ? 0x30 : 0x31;\n tmpToHash[1] = packetType & PACKET_TYPE_MASK;\n new DataView(tmpToHash.buffer).setUint32(2, generationID, false);\n tmpToHash.set(this.ivStruct, 6);\n\n const hash = createHash(\"sha256\").update(tmpToHash).digest();\n kn = {\n key: Uint8Array.from(hash.slice(0, 16)),\n nonce: Uint8Array.from(hash.slice(16, 32)),\n gen: generationID,\n };\n this.#cachedKeys.set(cacheKey, kn);\n }\n\n const key = Uint8Array.from(kn.key);\n key[0] = (key[0] !== undefined ? key[0] : 0) ^ ((packetID >> 8) & 0xff);\n key[1] = (key[1] !== undefined ? key[1] : 0) ^ (packetID & 0xff);\n\n return [key, kn.nonce];\n }\n\n encrypt(\n packetType: number,\n packetID: number,\n generationID: number,\n header: Uint8Array,\n plaintext: Uint8Array,\n dummy: boolean,\n unencrypted: boolean,\n ): [ciphertext: Uint8Array, mac: Uint8Array] {\n if (packetType === INIT1_PACKET_TYPE) {\n return [plaintext, INIT1_MAC];\n }\n if (unencrypted) {\n return [plaintext, this.fakeSignature];\n }\n\n const [key, nonce] = this.getKeyNonce(false, packetID, generationID, packetType, dummy);\n const eax = new EAX(key);\n return eax.encrypt(nonce, header, plaintext);\n }\n\n decrypt(\n packetType: number,\n packetID: number,\n generationID: number,\n header: Uint8Array,\n ciphertext: Uint8Array,\n tag: Uint8Array,\n dummy: boolean,\n unencrypted: boolean,\n ): Uint8Array {\n if (packetType === INIT1_PACKET_TYPE) {\n return ciphertext;\n }\n if (unencrypted) {\n const fsSub = tag.slice(0, FAKE_SIGNATURE_SIZE);\n if (!Buffer.from(fsSub).equals(Buffer.from(this.fakeSignature))) {\n throw new FakeSignatureMismatchError();\n }\n return ciphertext;\n }\n\n const [key, nonce] = this.getKeyNonce(true, packetID, generationID, packetType, dummy);\n const eax = new EAX(key);\n return eax.decrypt(nonce, header, ciphertext, tag);\n }\n\n #getSharedSecret(serverPubKey: import(\"node:crypto\").KeyObject): Uint8Array {\n const privJwk = this.identity.privateKey.export({ format: \"jwk\" }) as {\n d: string;\n };\n const pubJwk = serverPubKey.export({ format: \"jwk\" }) as {\n x: string;\n y: string;\n };\n\n const ecdh = createECDH(\"prime256v1\");\n const dBytes = Buffer.from(privJwk.d, \"base64url\");\n ecdh.setPrivateKey(dBytes);\n\n const xBytes = base64UrlToBytes(pubJwk.x, 32);\n const yBytes = base64UrlToBytes(pubJwk.y, 32);\n const uncompressed = Buffer.alloc(65);\n uncompressed[0] = 0x04;\n xBytes.copy(uncompressed, 1);\n yBytes.copy(uncompressed, 33);\n\n const rawSecret = ecdh.computeSecret(uncompressed);\n return createHash(\"sha1\").update(rawSecret).digest();\n }\n}\n\n// ---- Helpers ----------------------------------------------------------------\n\nfunction makeCacheKey(fromServer: boolean, packetType: number, generationID: number): bigint {\n let key = 0n;\n if (fromServer) key |= 1n << 40n;\n key |= BigInt(packetType & PACKET_TYPE_MASK) << 32n;\n key |= BigInt(generationID);\n return key;\n}\n\nfunction bytesToBigInt(bytes: Uint8Array): bigint {\n let result = 0n;\n for (const b of bytes) result = (result << 8n) | BigInt(b);\n return result;\n}\n\nfunction bigIntToBytes(value: bigint, size: number): Uint8Array {\n const result = new Uint8Array(size);\n let v = value;\n for (let i = size - 1; i >= 0; i--) {\n result[i] = Number(v & 0xffn);\n v >>= 8n;\n }\n return result;\n}\n\nfunction base64UrlToBytes(b64url: string, size: number): Buffer {\n const buf = Buffer.from(b64url, \"base64url\");\n if (buf.length === size) return buf;\n const padded = Buffer.alloc(size);\n buf.copy(padded, size - buf.length);\n return padded;\n}\n"],"mappings":"0EAGA,IAAM,EAAe,EACf,EAAiB,GAMV,EAAb,KAAiB,CACf,GAEA,YAAY,EAAiB,CAC3B,GAAI,EAAI,SAAW,GAAI,MAAU,MAAM,4BAA4B,EACnE,KAAK,GAAO,CACd,CAEA,QACE,EACA,EACA,EAC2C,CAC3C,IAAM,EAAQ,KAAK,GAAM,EAAG,CAAK,EAC3B,EAAQ,KAAK,GAAM,EAAG,CAAM,EAE5B,EAAa,EAAO,KAAK,GAAM,EAAO,CAAS,EAE/C,EAAQ,KAAK,GAAM,EAAG,CAAU,EAEhC,EAAM,IAAI,WAAW,CAAY,EACvC,IAAK,IAAI,EAAI,EAAG,EAAI,EAAc,IAChC,EAAI,GAAK,EAAM,GAAM,EAAM,GAAM,EAAM,GAGzC,MAAO,CAAC,EAAY,CAAG,CACzB,CAEA,QACE,EACA,EACA,EACA,EACY,CACZ,IAA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AAO,MAAM,EAAE,EACpC,EAAa,GAAK,EAClB,EAAO,KAAK,EAAc,CAAC,EAC3B,EAAO,KAAK,EAAc,EAAE,EAE5B,IAAM,EAAY,EAAK,cAAc,CAAY,EACjD,OAAA,EAAO,EAAA,WAAA,CAAW,MAAM,CAAC,CAAC,OAAO,CAAS,CAAC,CAAC,OAAO,CACrD,CACF,EAIA,SAAS,EAAa,EAAqB,EAAoB,EAA8B,CAC3F,IAAI,EAAM,GAIV,OAHI,IAAY,GAAO,IAAM,KAC7B,GAAO,OAAO,EAAa,CAAgB,GAAK,IAChD,GAAO,OAAO,CAAY,EACnB,CACT,CAEA,SAAS,EAAc,EAA2B,CAChD,IAAI,EAAS,GACb,IAAK,IAAM,KAAK,EAAO,EAAU,GAAU,GAAM,OAAO,CAAC,EACzD,OAAO,CACT,CAEA,SAAS,EAAc,EAAe,EAA0B,CAC9D,IAAM,EAAS,IAAI,WAAW,CAAI,EAC9B,EAAI,EACR,IAAK,IAAI,EAAI,EAAO,EAAG,GAAK,EAAG,IAC7B,EAAO,GAAK,OAAO,EAAI,IAAK,EAC5B,IAAM,GAER,OAAO,CACT,CAEA,SAAS,EAAiB,EAAgB,EAAsB,CAC9D,IAAM,EAAM,OAAO,KAAK,EAAQ,WAAW,EAC3C,GAAI,EAAI,SAAW,EAAM,OAAO,EAChC,IAAM,EAAS,OAAO,MAAM,CAAI,EAEhC,OADA,EAAI,KAAK,EAAQ,EAAO,EAAI,MAAM,EAC3B,CACT"}
|
package/dist/discovery/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../resolver-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../resolver-DCcmyWSK.cjs");exports.Resolver=e.t;
|
package/dist/discovery/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as e } from "../resolver-
|
|
1
|
+
import { t as e } from "../resolver-6B8dI9gr.js";
|
|
2
2
|
export { e as Resolver };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../src/discovery/resolver.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../src/discovery/resolver.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAQhD,qBAAa,QAAQ;;gBAGP,IAAI,GAAE,MAAmB;IAE/B,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;CA+GhF"}
|
|
@@ -1,32 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n
|
|
3
|
-
import {
|
|
1
|
+
import { o as e, r as t } from "./address-BfmovVpp.js";
|
|
2
|
+
import { n } from "./crypt-handshake-DziOY4Lq.js";
|
|
3
|
+
import { isIP as r } from "node:net";
|
|
4
|
+
import { createSocket as i } from "node:dgram";
|
|
4
5
|
//#region src/transport/packet.ts
|
|
5
|
-
var
|
|
6
|
+
var a = /* @__PURE__ */ function(e) {
|
|
6
7
|
return e[e.Voice = 0] = "Voice", e[e.VoiceWhisper = 1] = "VoiceWhisper", e[e.Command = 2] = "Command", e[e.CommandLow = 3] = "CommandLow", e[e.Ping = 4] = "Ping", e[e.Pong = 5] = "Pong", e[e.Ack = 6] = "Ack", e[e.AckLow = 7] = "AckLow", e[e.Init1 = 8] = "Init1", e;
|
|
7
|
-
}({}),
|
|
8
|
+
}({}), o = /* @__PURE__ */ function(e) {
|
|
8
9
|
return e[e.Fragmented = 16] = "Fragmented", e[e.NewProtocol = 32] = "NewProtocol", e[e.Compressed = 64] = "Compressed", e[e.Unencrypted = 128] = "Unencrypted", e;
|
|
9
10
|
}({});
|
|
10
|
-
function
|
|
11
|
+
function s(e) {
|
|
11
12
|
return e.typeFlagged & 15;
|
|
12
13
|
}
|
|
13
|
-
function
|
|
14
|
+
function c(e) {
|
|
14
15
|
return e.typeFlagged & 240;
|
|
15
16
|
}
|
|
16
|
-
function
|
|
17
|
-
return (
|
|
17
|
+
function l(e) {
|
|
18
|
+
return !!(c(e) & 128);
|
|
18
19
|
}
|
|
19
|
-
function
|
|
20
|
+
function u(e) {
|
|
20
21
|
let t = /* @__PURE__ */ new Uint8Array(5), n = new DataView(t.buffer);
|
|
21
22
|
return n.setUint16(0, e.id, !1), n.setUint16(2, e.clientID, !1), t[4] = e.typeFlagged, t;
|
|
22
23
|
}
|
|
23
|
-
function
|
|
24
|
+
function d(e) {
|
|
24
25
|
return {
|
|
25
26
|
id: new DataView(e.buffer, e.byteOffset, e.byteLength).getUint16(0, !1),
|
|
26
27
|
typeFlagged: e[2]
|
|
27
28
|
};
|
|
28
29
|
}
|
|
29
|
-
function
|
|
30
|
+
function f(e) {
|
|
30
31
|
let t = new DataView(e.buffer, e.byteOffset, e.byteLength);
|
|
31
32
|
return {
|
|
32
33
|
id: t.getUint16(0, !1),
|
|
@@ -36,7 +37,7 @@ function u(e) {
|
|
|
36
37
|
}
|
|
37
38
|
//#endregion
|
|
38
39
|
//#region src/transport/generation-window.ts
|
|
39
|
-
var
|
|
40
|
+
var p = class {
|
|
40
41
|
#e = 0;
|
|
41
42
|
#t = 0;
|
|
42
43
|
#n;
|
|
@@ -82,10 +83,10 @@ var d = class {
|
|
|
82
83
|
reset() {
|
|
83
84
|
this.#e = 0, this.#t = 0;
|
|
84
85
|
}
|
|
85
|
-
},
|
|
86
|
-
#e = new Int32Array(
|
|
86
|
+
}, m = 4096, h = class {
|
|
87
|
+
#e = new Int32Array(m);
|
|
87
88
|
decompress(e) {
|
|
88
|
-
let { headerLen: t, decompressedSize: n, flags: r } =
|
|
89
|
+
let { headerLen: t, decompressedSize: n, flags: r } = g(e), i = new Uint8Array(n);
|
|
89
90
|
if (!(r & 1)) return i.set(e.slice(t, t + n)), i;
|
|
90
91
|
this.#e.fill(0);
|
|
91
92
|
let a = {
|
|
@@ -142,7 +143,7 @@ var d = class {
|
|
|
142
143
|
}
|
|
143
144
|
}
|
|
144
145
|
};
|
|
145
|
-
function
|
|
146
|
+
function g(e) {
|
|
146
147
|
if (e.length < 3) throw Error("QuickLZ: data too short");
|
|
147
148
|
let t = e[0];
|
|
148
149
|
if ((t >> 2 & 3) != 1) throw Error("QuickLZ: only level 1 is supported");
|
|
@@ -157,7 +158,7 @@ function m(e) {
|
|
|
157
158
|
}
|
|
158
159
|
//#endregion
|
|
159
160
|
//#region src/transport/handler.ts
|
|
160
|
-
var
|
|
161
|
+
var _ = 1024, v = 5e3, y = 6e4, b = 1e3, x = 8, S = 3, C = 5, w = 500, T = 100, E = class {
|
|
161
162
|
onPacket = null;
|
|
162
163
|
onClosed = null;
|
|
163
164
|
#e;
|
|
@@ -170,10 +171,10 @@ var h = 500, g = 1024, _ = 5e3, v = 6e4, y = 1e3, b = 5, x = 8, S = 3, C = 500,
|
|
|
170
171
|
#s = Date.now();
|
|
171
172
|
#c = /* @__PURE__ */ new Uint16Array(9);
|
|
172
173
|
#l = /* @__PURE__ */ new Uint32Array(9);
|
|
173
|
-
#u = new
|
|
174
|
-
#d = new
|
|
175
|
-
#f = new
|
|
176
|
-
#p = new
|
|
174
|
+
#u = new p(65536, _);
|
|
175
|
+
#d = new p(65536, _);
|
|
176
|
+
#f = new p(65536, _);
|
|
177
|
+
#p = new p(65536, _);
|
|
177
178
|
#m = /* @__PURE__ */ new Map();
|
|
178
179
|
#h = /* @__PURE__ */ new Map();
|
|
179
180
|
#g = /* @__PURE__ */ new Map();
|
|
@@ -185,10 +186,12 @@ var h = 500, g = 1024, _ = 5e3, v = 6e4, y = 1e3, b = 5, x = 8, S = 3, C = 500,
|
|
|
185
186
|
this.#r = e;
|
|
186
187
|
}
|
|
187
188
|
connect(e) {
|
|
188
|
-
return new Promise((
|
|
189
|
-
let
|
|
190
|
-
|
|
191
|
-
|
|
189
|
+
return new Promise((n, a) => {
|
|
190
|
+
let { host: o, port: s } = t(e), c = i(r(o) === 6 ? "udp6" : "udp4"), l = (e) => {
|
|
191
|
+
c.close(), a(e);
|
|
192
|
+
};
|
|
193
|
+
c.once("error", l), c.connect(parseInt(s, 10), o, () => {
|
|
194
|
+
c.off("error", l), this.start(c), n();
|
|
192
195
|
});
|
|
193
196
|
});
|
|
194
197
|
}
|
|
@@ -197,123 +200,148 @@ var h = 500, g = 1024, _ = 5e3, v = 6e4, y = 1e3, b = 5, x = 8, S = 3, C = 500,
|
|
|
197
200
|
this.#s = Date.now(), this.#x(new Uint8Array(e.buffer, e.byteOffset, e.byteLength));
|
|
198
201
|
}), e.on("error", (e) => {
|
|
199
202
|
this.#t.error("udp error", e), this.#R(e);
|
|
200
|
-
}), e.on("close", () => this.#R(null)), this.#c[
|
|
201
|
-
let
|
|
202
|
-
|
|
203
|
-
let
|
|
204
|
-
this.#e.cryptoInitComplete && this.sendPacket(
|
|
205
|
-
},
|
|
206
|
-
this.#a = () => clearInterval(
|
|
207
|
-
let
|
|
208
|
-
this.#o = () => clearInterval(
|
|
203
|
+
}), e.on("close", () => this.#R(null)), this.#c[a.Command] = 1, this.#c[a.Init1] = 101;
|
|
204
|
+
let t = n(this.#e, null);
|
|
205
|
+
t && this.#y(a.Init1, t, 0);
|
|
206
|
+
let r = setInterval(() => {
|
|
207
|
+
this.#e.cryptoInitComplete && this.sendPacket(a.Ping, /* @__PURE__ */ new Uint8Array(), o.Unencrypted);
|
|
208
|
+
}, v);
|
|
209
|
+
this.#a = () => clearInterval(r);
|
|
210
|
+
let i = setInterval(() => this.#I(), T);
|
|
211
|
+
this.#o = () => clearInterval(i);
|
|
209
212
|
}
|
|
210
213
|
receivedFinalInitAck() {
|
|
211
214
|
this.#_ = null;
|
|
212
215
|
}
|
|
213
216
|
sendPacket(e, t, n) {
|
|
214
|
-
let
|
|
215
|
-
if (t.length > 487 && e !==
|
|
216
|
-
this.#v(e, t, n,
|
|
217
|
+
let r = !this.#e.cryptoInitComplete;
|
|
218
|
+
if (t.length > 487 && e !== a.Voice && e !== a.VoiceWhisper) {
|
|
219
|
+
this.#v(e, t, n, r);
|
|
217
220
|
return;
|
|
218
221
|
}
|
|
219
|
-
this.#y(e, t, n,
|
|
222
|
+
this.#y(e, t, n, r);
|
|
220
223
|
}
|
|
221
224
|
sendVoicePacket(e, t) {
|
|
222
|
-
let n = this.#c[
|
|
223
|
-
this.#c[
|
|
224
|
-
let
|
|
225
|
+
let n = this.#c[a.Voice], r = this.#l[a.Voice];
|
|
226
|
+
this.#c[a.Voice] = n + 1 & 65535, this.#c[a.Voice] === 0 && this.#l[a.Voice]++;
|
|
227
|
+
let i = S + e.length, s = new Uint8Array(i);
|
|
225
228
|
new DataView(s.buffer).setUint16(0, n, !1), s[2] = t, s.set(e, S);
|
|
226
|
-
let
|
|
227
|
-
typeFlagged:
|
|
229
|
+
let c = u({
|
|
230
|
+
typeFlagged: a.Voice | o.Unencrypted,
|
|
228
231
|
id: n,
|
|
229
232
|
clientID: this.#r,
|
|
230
|
-
generationID:
|
|
233
|
+
generationID: r,
|
|
231
234
|
data: s,
|
|
232
235
|
receivedAt: 0
|
|
233
|
-
}),
|
|
234
|
-
|
|
236
|
+
}), l = new Uint8Array(13 + i);
|
|
237
|
+
l.set(this.#e.fakeSignature, 0), l.set(c, x), l.set(s, 13), this.#b(l);
|
|
238
|
+
}
|
|
239
|
+
sendWhisperPacket(e, t, n) {
|
|
240
|
+
if (t.length === 0) throw Error("whisper requires at least one target");
|
|
241
|
+
if (t.length > 32) throw Error("too many whisper targets");
|
|
242
|
+
if (t.some((e) => !Number.isInteger(e) || e < 0 || e > 65535)) throw RangeError("invalid whisper target");
|
|
243
|
+
let r = this.#c[a.VoiceWhisper], i = this.#l[a.VoiceWhisper];
|
|
244
|
+
this.#c[a.VoiceWhisper] = r + 1 & 65535, this.#c[a.VoiceWhisper] === 0 && (this.#l[a.VoiceWhisper] = i + 1 >>> 0);
|
|
245
|
+
let s = C + t.length * 2 + e.length, c = new Uint8Array(s), l = new DataView(c.buffer);
|
|
246
|
+
l.setUint16(0, r, !1), c[2] = n, c[3] = 0, c[4] = t.length;
|
|
247
|
+
for (let e = 0; e < t.length; e++) l.setUint16(C + e * 2, t[e], !1);
|
|
248
|
+
c.set(e, C + t.length * 2);
|
|
249
|
+
let d = u({
|
|
250
|
+
typeFlagged: a.VoiceWhisper | o.Unencrypted,
|
|
251
|
+
id: r,
|
|
252
|
+
clientID: this.#r,
|
|
253
|
+
generationID: i,
|
|
254
|
+
data: c,
|
|
255
|
+
receivedAt: 0
|
|
256
|
+
}), f = new Uint8Array(13 + s);
|
|
257
|
+
f.set(this.#e.fakeSignature, 0), f.set(d, x), f.set(c, 13), this.#b(f);
|
|
235
258
|
}
|
|
236
259
|
close() {
|
|
237
260
|
this.#i || (this.#i = !0, this.#a?.(), this.#o?.(), this.#n?.close());
|
|
238
261
|
}
|
|
239
262
|
#v(e, t, n, r) {
|
|
240
|
-
let
|
|
241
|
-
for (;
|
|
242
|
-
let
|
|
243
|
-
|
|
263
|
+
let i = 0, a = !0;
|
|
264
|
+
for (; i < t.length;) {
|
|
265
|
+
let s = Math.min(t.length - i, 487), c = i + s === t.length, l = n;
|
|
266
|
+
a !== c && (l |= o.Fragmented), this.#y(e, t.slice(i, i + s), l, r), i += s, a = !1;
|
|
244
267
|
}
|
|
245
268
|
}
|
|
246
269
|
#y(e, t, n, r = !this.#e.cryptoInitComplete) {
|
|
247
|
-
n =
|
|
248
|
-
let [
|
|
270
|
+
n = D(e, n);
|
|
271
|
+
let [i, a] = this.#P(e), s = {
|
|
249
272
|
typeFlagged: e | n,
|
|
250
|
-
id:
|
|
273
|
+
id: i,
|
|
251
274
|
clientID: this.#r,
|
|
252
|
-
generationID:
|
|
275
|
+
generationID: a,
|
|
253
276
|
data: t,
|
|
254
277
|
receivedAt: 0
|
|
255
|
-
},
|
|
256
|
-
p.set(f.slice(0, x), 0), p.set(
|
|
278
|
+
}, c = (n & o.Unencrypted) !== 0, l = u(s), [d, f] = this.#e.encrypt(e, i, a, l, t, r, c), p = new Uint8Array(13 + d.length);
|
|
279
|
+
p.set(f.slice(0, x), 0), p.set(l, x), p.set(d, 13), this.#b(p);
|
|
257
280
|
let m = {
|
|
258
281
|
packet: s,
|
|
259
282
|
firstSend: Date.now(),
|
|
260
283
|
lastSend: Date.now(),
|
|
261
284
|
retryCount: 0,
|
|
262
|
-
nextInterval:
|
|
285
|
+
nextInterval: w
|
|
263
286
|
};
|
|
264
287
|
this.#F(e, s, m);
|
|
265
288
|
}
|
|
266
289
|
#b(e) {
|
|
267
|
-
this.#n
|
|
268
|
-
|
|
269
|
-
|
|
290
|
+
if (this.#n) try {
|
|
291
|
+
this.#n.send(Buffer.from(e), (e) => {
|
|
292
|
+
e && this.#t.warn("udp send error", e);
|
|
293
|
+
});
|
|
294
|
+
} catch (e) {
|
|
295
|
+
let t = e instanceof Error ? e : Error(String(e));
|
|
296
|
+
this.#t.error("udp send failed", t), this.#R(t);
|
|
297
|
+
}
|
|
270
298
|
}
|
|
271
299
|
#x(e) {
|
|
272
300
|
if (e.length < 11) return;
|
|
273
|
-
let t = e.slice(0, x), n = e.slice(x, 11),
|
|
274
|
-
...
|
|
301
|
+
let t = e.slice(0, x), n = e.slice(x, 11), r = e.slice(11), i = d(n), o = {
|
|
302
|
+
...i,
|
|
275
303
|
clientID: 0,
|
|
276
|
-
generationID: this.#S(
|
|
304
|
+
generationID: this.#S(i.id, i.typeFlagged & 15),
|
|
277
305
|
data: /* @__PURE__ */ new Uint8Array(),
|
|
278
306
|
receivedAt: Date.now()
|
|
279
|
-
}, c = this.#C(
|
|
307
|
+
}, c = this.#C(o, n, r, t);
|
|
280
308
|
if (c !== null) {
|
|
281
|
-
if (
|
|
282
|
-
this.#E(
|
|
309
|
+
if (o.data = c.plaintext, s(o) === a.Ping) {
|
|
310
|
+
this.#E(o.id, c.dummyUsed);
|
|
283
311
|
return;
|
|
284
312
|
}
|
|
285
|
-
this.#w(
|
|
313
|
+
this.#w(o, c.dummyUsed) && (this.#D(o), this.#N(o));
|
|
286
314
|
}
|
|
287
315
|
}
|
|
288
316
|
#S(e, t) {
|
|
289
317
|
switch (t) {
|
|
290
|
-
case
|
|
291
|
-
case
|
|
292
|
-
case
|
|
293
|
-
case
|
|
318
|
+
case a.Command: return this.#u.getGeneration(e);
|
|
319
|
+
case a.CommandLow: return this.#d.getGeneration(e);
|
|
320
|
+
case a.Ack: return this.#f.getGeneration(e);
|
|
321
|
+
case a.AckLow: return this.#p.getGeneration(e);
|
|
294
322
|
default: return 0;
|
|
295
323
|
}
|
|
296
324
|
}
|
|
297
|
-
#C(e, t, n,
|
|
298
|
-
let
|
|
325
|
+
#C(e, t, n, r) {
|
|
326
|
+
let i = (c(e) & o.Unencrypted) !== 0, l = !this.#e.cryptoInitComplete, u = l, d = s(e), f = e.generationID;
|
|
299
327
|
try {
|
|
300
328
|
return {
|
|
301
|
-
plaintext: this.#e.decrypt(d, e.id, f, t, n,
|
|
329
|
+
plaintext: this.#e.decrypt(d, e.id, f, t, n, r, l, i),
|
|
302
330
|
dummyUsed: u
|
|
303
331
|
};
|
|
304
332
|
} catch {
|
|
305
|
-
for (let
|
|
306
|
-
let
|
|
307
|
-
if (!(
|
|
333
|
+
for (let i of [-1, 1]) {
|
|
334
|
+
let a = f + i;
|
|
335
|
+
if (!(a < 0)) try {
|
|
308
336
|
return {
|
|
309
|
-
plaintext: this.#e.decrypt(d, e.id,
|
|
337
|
+
plaintext: this.#e.decrypt(d, e.id, a, t, n, r, !1, !1),
|
|
310
338
|
dummyUsed: !1
|
|
311
339
|
};
|
|
312
340
|
} catch {}
|
|
313
341
|
}
|
|
314
|
-
if (d ===
|
|
342
|
+
if (d === a.Command || d === a.CommandLow || d === a.Ack) try {
|
|
315
343
|
return {
|
|
316
|
-
plaintext: this.#e.decrypt(d, e.id, f, t, n,
|
|
344
|
+
plaintext: this.#e.decrypt(d, e.id, f, t, n, r, !0, i),
|
|
317
345
|
dummyUsed: !0
|
|
318
346
|
};
|
|
319
347
|
} catch {}
|
|
@@ -321,10 +349,10 @@ var h = 500, g = 1024, _ = 5e3, v = 6e4, y = 1e3, b = 5, x = 8, S = 3, C = 500,
|
|
|
321
349
|
}
|
|
322
350
|
}
|
|
323
351
|
#w(e, t) {
|
|
324
|
-
let n =
|
|
325
|
-
if (n !==
|
|
326
|
-
let
|
|
327
|
-
return
|
|
352
|
+
let n = s(e);
|
|
353
|
+
if (n !== a.Command && n !== a.CommandLow) return !0;
|
|
354
|
+
let r = n === a.Command ? this.#u : this.#d, i = n === a.Command ? a.Ack : a.AckLow;
|
|
355
|
+
return r.isInWindow(e.id) ? (this.#T(e.id, i, t), !0) : (r.isOldPacket(e.id) && this.#T(e.id, i, t), !1);
|
|
328
356
|
}
|
|
329
357
|
#T(e, t, n) {
|
|
330
358
|
let r = /* @__PURE__ */ new Uint8Array(2);
|
|
@@ -332,39 +360,39 @@ var h = 500, g = 1024, _ = 5e3, v = 6e4, y = 1e3, b = 5, x = 8, S = 3, C = 500,
|
|
|
332
360
|
}
|
|
333
361
|
#E(e, t) {
|
|
334
362
|
let n = /* @__PURE__ */ new Uint8Array(2);
|
|
335
|
-
new DataView(n.buffer).setUint16(0, e, !1), this.#y(
|
|
363
|
+
new DataView(n.buffer).setUint16(0, e, !1), this.#y(a.Pong, n, o.Unencrypted, t);
|
|
336
364
|
}
|
|
337
365
|
#D(e) {
|
|
338
|
-
let t =
|
|
339
|
-
if (t !==
|
|
366
|
+
let t = s(e);
|
|
367
|
+
if (t !== a.Command && t !== a.CommandLow) {
|
|
340
368
|
this.onPacket?.(e);
|
|
341
369
|
return;
|
|
342
370
|
}
|
|
343
|
-
let n = t ===
|
|
344
|
-
for (
|
|
345
|
-
let e = n ? this.#O : this.#k, t =
|
|
371
|
+
let n = t === a.Command, r = n ? this.#m : this.#h, i = n ? this.#u : this.#d;
|
|
372
|
+
for (r.set(e.id, e), n ? this.#A(r, i, !0) : this.#A(r, i, !1);;) {
|
|
373
|
+
let e = n ? this.#O : this.#k, t = r.get(e);
|
|
346
374
|
if (t === void 0) break;
|
|
347
|
-
let
|
|
348
|
-
if (!
|
|
349
|
-
let [
|
|
350
|
-
n ? this.#O = s : this.#k = s, this.#M(
|
|
375
|
+
let a = this.#j(t, r, e, i);
|
|
376
|
+
if (!a) break;
|
|
377
|
+
let [o, s] = a;
|
|
378
|
+
n ? this.#O = s : this.#k = s, this.#M(o), this.onPacket?.(o);
|
|
351
379
|
}
|
|
352
380
|
}
|
|
353
381
|
#O = 0;
|
|
354
382
|
#k = 0;
|
|
355
383
|
#A(e, t, n) {
|
|
356
384
|
let r = n ? this.#O : this.#k;
|
|
357
|
-
for (; !e.has(r) &&
|
|
385
|
+
for (; !e.has(r) && O(e, r);) r = r + 1 & 65535, t.advance(1);
|
|
358
386
|
n ? this.#O = r : this.#k = r;
|
|
359
387
|
}
|
|
360
388
|
#j(e, t, n, r) {
|
|
361
|
-
if ((
|
|
362
|
-
let
|
|
389
|
+
if ((c(e) & o.Fragmented) === 0) return t.delete(n), r.advance(1), [e, n + 1 & 65535];
|
|
390
|
+
let i = [], a = 0, s = n, l = !1, u = !1;
|
|
363
391
|
for (;;) {
|
|
364
|
-
let e = t.get(
|
|
392
|
+
let e = t.get(s);
|
|
365
393
|
if (!e) return null;
|
|
366
|
-
|
|
367
|
-
let n = (
|
|
394
|
+
i.push(e), a += e.data.length;
|
|
395
|
+
let n = (c(e) & o.Fragmented) !== 0;
|
|
368
396
|
if (!l) {
|
|
369
397
|
if (l = !0, !n) {
|
|
370
398
|
u = !0;
|
|
@@ -374,16 +402,16 @@ var h = 500, g = 1024, _ = 5e3, v = 6e4, y = 1e3, b = 5, x = 8, S = 3, C = 500,
|
|
|
374
402
|
u = !0;
|
|
375
403
|
break;
|
|
376
404
|
}
|
|
377
|
-
|
|
405
|
+
s = s + 1 & 65535;
|
|
378
406
|
}
|
|
379
407
|
if (!u) return null;
|
|
380
|
-
let d = new Uint8Array(
|
|
381
|
-
for (let e of
|
|
382
|
-
return e.data = d, e.typeFlagged &= ~
|
|
408
|
+
let d = new Uint8Array(a), f = 0;
|
|
409
|
+
for (let e of i) d.set(e.data, f), f += e.data.length, t.delete(n), r.advance(1), n = n + 1 & 65535;
|
|
410
|
+
return e.data = d, e.typeFlagged &= ~o.Fragmented, [e, n];
|
|
383
411
|
}
|
|
384
412
|
#M(e) {
|
|
385
|
-
if ((
|
|
386
|
-
e.data = new
|
|
413
|
+
if ((c(e) & o.Compressed) !== 0) try {
|
|
414
|
+
e.data = new h().decompress(e.data), e.typeFlagged &= ~o.Compressed;
|
|
387
415
|
} catch (t) {
|
|
388
416
|
this.#t.debug("decompression failed", {
|
|
389
417
|
id: e.id,
|
|
@@ -392,39 +420,39 @@ var h = 500, g = 1024, _ = 5e3, v = 6e4, y = 1e3, b = 5, x = 8, S = 3, C = 500,
|
|
|
392
420
|
}
|
|
393
421
|
}
|
|
394
422
|
#N(e) {
|
|
395
|
-
let t =
|
|
396
|
-
if (t ===
|
|
423
|
+
let t = s(e);
|
|
424
|
+
if (t === a.Init1) {
|
|
397
425
|
this.#_ = null;
|
|
398
426
|
return;
|
|
399
427
|
}
|
|
400
|
-
if ((t ===
|
|
401
|
-
let n = new DataView(e.data.buffer, e.data.byteOffset).getUint16(0, !1),
|
|
402
|
-
this.#g.delete(
|
|
428
|
+
if ((t === a.Ack || t === a.AckLow) && e.data.length >= 2) {
|
|
429
|
+
let n = new DataView(e.data.buffer, e.data.byteOffset).getUint16(0, !1), r = (t === a.Ack ? a.Command : a.CommandLow) << 16 | n;
|
|
430
|
+
this.#g.delete(r);
|
|
403
431
|
}
|
|
404
432
|
}
|
|
405
433
|
#P(e) {
|
|
406
434
|
let t = this.#c[e], n = this.#l[e];
|
|
407
|
-
return e ===
|
|
435
|
+
return e === a.Init1 ? [t, n] : (this.#c[e] = t + 1 & 65535, this.#c[e] === 0 && (this.#l[e] = n + 1 >>> 0), e === a.Command ? this.#f.advanceToExcluded(t) : e === a.CommandLow && this.#p.advanceToExcluded(t), [t, n]);
|
|
408
436
|
}
|
|
409
437
|
#F(e, t, n) {
|
|
410
|
-
if (e ===
|
|
438
|
+
if (e === a.Init1) {
|
|
411
439
|
this.#_ = n;
|
|
412
440
|
return;
|
|
413
441
|
}
|
|
414
|
-
if (e ===
|
|
442
|
+
if (e === a.Command || e === a.CommandLow) {
|
|
415
443
|
let r = e << 16 | t.id;
|
|
416
444
|
this.#g.set(r, n);
|
|
417
445
|
}
|
|
418
446
|
}
|
|
419
447
|
#I() {
|
|
420
448
|
let e = Date.now();
|
|
421
|
-
if (e - this.#s >
|
|
449
|
+
if (e - this.#s > y) {
|
|
422
450
|
this.#t.warn("idle timeout"), this.#R(/* @__PURE__ */ Error("idle timeout"));
|
|
423
451
|
return;
|
|
424
452
|
}
|
|
425
453
|
this.#_ && this.#L(this.#_, e);
|
|
426
454
|
for (let [t, n] of this.#g) {
|
|
427
|
-
if (e - n.firstSend >
|
|
455
|
+
if (e - n.firstSend > y) {
|
|
428
456
|
this.#g.delete(t), this.#R(/* @__PURE__ */ Error("packet ack timeout"));
|
|
429
457
|
return;
|
|
430
458
|
}
|
|
@@ -433,23 +461,23 @@ var h = 500, g = 1024, _ = 5e3, v = 6e4, y = 1e3, b = 5, x = 8, S = 3, C = 500,
|
|
|
433
461
|
}
|
|
434
462
|
#L(e, t) {
|
|
435
463
|
if (t - e.lastSend < e.nextInterval) return;
|
|
436
|
-
e.lastSend = t, e.retryCount++, e.nextInterval = Math.min(e.nextInterval * 2,
|
|
437
|
-
let n = !this.#e.cryptoInitComplete, r = (
|
|
438
|
-
f.set(d.slice(0, x), 0), f.set(
|
|
464
|
+
e.lastSend = t, e.retryCount++, e.nextInterval = Math.min(e.nextInterval * 2, b);
|
|
465
|
+
let n = !this.#e.cryptoInitComplete, r = (c(e.packet) & o.Unencrypted) !== 0, i = u(e.packet), a = s(e.packet), [l, d] = this.#e.encrypt(a, e.packet.id, e.packet.generationID, i, e.packet.data, n, r), f = new Uint8Array(13 + l.length);
|
|
466
|
+
f.set(d.slice(0, x), 0), f.set(i, x), f.set(l, 13), this.#b(f);
|
|
439
467
|
}
|
|
440
468
|
#R(e) {
|
|
441
469
|
this.#i || (this.close(), this.onClosed?.(e));
|
|
442
470
|
}
|
|
443
471
|
};
|
|
444
|
-
function E(e, t) {
|
|
445
|
-
return e === r.Command || e === r.CommandLow ? t | i.NewProtocol : t;
|
|
446
|
-
}
|
|
447
472
|
function D(e, t) {
|
|
473
|
+
return e === a.Command || e === a.CommandLow ? t | o.NewProtocol : t;
|
|
474
|
+
}
|
|
475
|
+
function O(e, t) {
|
|
448
476
|
let n = Date.now();
|
|
449
477
|
for (let [r, i] of e) if ((r - t + 65536 & 65535) < 32768 && n - i.receivedAt > 5e3) return !0;
|
|
450
478
|
return !1;
|
|
451
479
|
}
|
|
452
480
|
//#endregion
|
|
453
|
-
export {
|
|
481
|
+
export { a, c, d, o as i, s as l, h as n, u as o, p as r, l as s, E as t, f as u };
|
|
454
482
|
|
|
455
|
-
//# sourceMappingURL=handler-
|
|
483
|
+
//# sourceMappingURL=handler-DI_abe9c.js.map
|