Improved key generation with factory pattern #120
Merged
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.
Fixes a TODO in the code:
eigensdk-go/cmd/egnkey/generate.go
Line 76 in a5629b0
Motivation
Updating to a factory pattern is smart to decouple object creation from its usage in our key generation logic. This change addresses the challenge of supporting multiple key types (ECDSA and BLS) in a scalable way.
Solution
The first I did was to include a KeyGenerator interface and two concrete implementations for ECDSA and BLS key types. The factory function, NewKeyGenerator, dynamically selects the appropriate generator based on input parameters, simplifying the generate function.
Open questions
Would someone mind if we wrote unit tests for the newly implemented factory pattern in our key generation system, particularly focusing on the dynamic selection logic of the NewKeyGenerator function and ensuring each key generator (ECDSA and BLS) behaves as expected under various input conditions? Since as for now the
egnkey
does not have any test cases.