refactor: update crypto HOF to Crypto class#36
Merged
Conversation
liangyuanruo
previously approved these changes
Jun 5, 2020
f685514 to
b62a828
Compare
3d4fcce to
92358d5
Compare
arshadali172
suggested changes
Jun 10, 2020
|
|
||
| if (verifiedContent) { | ||
| if (!this.publicSigningKey) { | ||
| throw new MissingPublicKeyError( |
There was a problem hiding this comment.
Again, should it be the responsibility of the constructor to check such things?
| if (err instanceof MissingPublicKeyError) { | ||
| throw err | ||
| } | ||
| return null |
There was a problem hiding this comment.
Seems odd that the caller of this function will not know the cause of the error?
Contributor
Author
There was a problem hiding this comment.
This was an early choice to follow how tweetnacl returns objects. If the encryption failed in anyway, then null is returned.
Instead of `publicKey`, `publicSigningKey` makes it more obvious of what the use of the key is for. Making constructor optional also allows users of the library to encrypt and decrypt without having to provide a public signing key if they do not want to and still be able to decrypt content without verified fields. Note that the default package initialisation still instantiates the library with a fallback key.
b62a828 to
8ce86a5
Compare
liangyuanruo
approved these changes
Jun 11, 2020
liangyuanruo
pushed a commit
that referenced
this pull request
Jan 27, 2021
* feat: add util/crypto.ts for helper methods used by new Crypto class * feat: rewrite crypto.ts functions as Crypto class and use in init * feat: update thrown error name in JSDoc of Webhook.authenticate * test(Crypto): update tests to use new class based instantiation * refactor(Crypto): change constructor to optional `publicSigningKey` Instead of `publicKey`, `publicSigningKey` makes it more obvious of what the use of the key is for. Making constructor optional also allows users of the library to encrypt and decrypt without having to provide a public signing key if they do not want to and still be able to decrypt content without verified fields. Note that the default package initialisation still instantiates the library with a fallback key. * refactor: allow optional constructor params * test(Crypto): add tests for 100% coverage * refactor: update import order * test: remove misleading comment
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.
Part two of the refactor, meant to keep the PR size manageable.
Related to #31
Note that this PR is pointing to part 1: Webhook HOF -> class refactor
The current chain is:
master -> webhooks -> crypto (this)