fix: resolve circular dependencies causing KeyEncoding undefined#928
Merged
Conversation
Break circular import cycles that could cause `TypeError: Cannot read property 'PKCS1' of undefined` depending on bundler module evaluation order. - Replace `instanceof KeyObject` in utils/conversion.ts with Symbol.toStringTag check to eliminate utils -> keys/classes cycle - Change 5 algorithm files (ed, rsa, ec, dsa, dhKeyPair) to import from keys/classes directly instead of the keys/ barrel, breaking keys/index -> generateKeyPair -> algorithm -> keys/index cycles - Add dpdm circular dependency detection to CI (validate-js workflow)
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
Resolves a circular dependency chain that caused
KeyEncodingto beundefinedat runtime, breaking key generation operations (RSA, EC, Ed, DSA, DH).Fixes #927
Changes
Break the import cycle
conversion.ts: Removed directimport { KeyObject }fromkeys/classes. Instead, duck-typesKeyObjectviaSymbol.toStringTag([object KeyObject]) to avoid the circular dependency while preserving correct behavior.dhKeyPair.ts,dsa.ts,ec.ts,ed.ts,rsa.ts: Changed imports from./keys(barrel export) to./keys/classes(direct), breaking the cycle path through the barrel's re-exports of../utils.CI guardrail
dpdmcircular dependency checker as a devDependency and"circular"script in the package.validate-js.ymlworkflow to prevent regressions.Testing
bun tscpasses cleanlybun circularreports no circular dependenciesKeyEncoding undefinedshould now work correctly