Fix TypeScript/ESLint errors, add unit tests, and fix failing SRP tests#619
Open
Moustafa-Elgammal wants to merge 5 commits intomorethanwords:masterfrom
Open
Conversation
Owner
|
Thank you for the PR! I'm actually using typescript@5.8.2 (as in pnpm-lock.yaml), so the issues that you fixed here is not actual, both Promise and Uint8Array. However, I could merge the tests part of the PR, if you create it again. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Uint8Array<ArrayBufferLike>generics andawait-thenablelint rule)subtleobject robust against test-environment timingTypeScript & ESLint fixes (47 files)
Uint8Array<ArrayBufferLike>→ explicit generic castsTypeScript 5.7 narrows
Uint8Arrayto carry its buffer type as a generic parameter. Many call sites passedUint8Array<ArrayBufferLike>whereUint8Array<ArrayBuffer>(orBlobPart[],BufferSource, etc.) was expected. Fixed with targetedascasts at each boundary:blobConstruct.ts— castblobPartstoBlobPart[]for theBlobconstructortl_utils.ts— castbuffer.buffertoArrayBufferinTLDeserialization, fixfetchRawBytesoverload signatures, and castgzipUncompressresult toUint8Array<ArrayBuffer>srp.ts— cast buffer arguments toUint8Array<ArrayBuffer>forinvokeCrypto('pbkdf2', ...)passcode/utils.ts— castsalttoUint8Array<ArrayBuffer>for WebCryptoPBKDF2paramsserviceWorker/stream.ts,rtmp.ts— cast body bytes toUint8Array<ArrayBuffer>forResponseconstructorsha1.ts,sha256.ts,aesCtrUtils.ts,aesCTR.ts,aesLocal.ts— cast digest/encrypt inputsp2PEncryptor.ts— cast encrypted buffer slicesPromise.all([...MaybePromise])arrays withas Promise<T>[]to satisfy theawait-thenableESLint ruleArray.prototype.at(-1)→ index replacementstarGiftInfo.tsxused.at(-1)which is not available in thees2015compilation target. Replaced witharr[arr.length - 1].subtle.ts— lazy crypto proxyThe original module captured
window.crypto.subtleat import time:In the vitest/jsdom environment (with
isolate: false), modules are evaluated during test collection — beforesetupFilesinstallsself.crypto. This could cause crypto operations to bind to an uninitialised or wrong subtle object.Replaced with a
Proxythat resolvesgetSubtle()on every call:SRP mock test vectors corrected
src/tests/srp.test.tshad two failing tests since thepasswordHashedandM1values insrc/mock/srp.tswere stale. A standalone Node.jswebcryptoscript independently computed the correct values by following the Telegram SRP spec step-by-step (SHA-256 → SHA-256 → PBKDF2-SHA512 × 100 000 → SHA-256). The code was verified correct; only the mock was wrong.Updated:
passwordHashed— correct 32-byte SHA-256 output of the full password-hashing chainM1— correct 32-byte proof-of-password value derived from the updated hashAmatched the existing mock exactly, confirming BigInteger modular exponentiation is correct.Test infrastructure
Docker test runner (
docker-compose.yaml) — addedtweb.testservice that runspnpm testinside the container, enabling reproducible CI-style test execution.Unit tests — replaced the monolithic
fixes.test.tswith four focused files:blobConstruct.test.tsblobConstructwith variousBlobPartinputsbufferConcats.test.tsbufferConcats+Uint8Array.prototype.concatpolyfillpromiseAll.test.tsPromise.allwith mixedMaybePromisearraystypeCasting.test.tsArrayBuffercasts,Responsebody castscrypto_methods.test.ts— the existingpbkdf2test had an empty body (all assertions were commented out). Replaced with assertions that verify output length (64 bytes / SHA-512) and determinism.Test results