Skip to content

refactor: update crypto HOF to Crypto class#36

Merged
karrui merged 9 commits intomasterfrom
feat/class-based-crypto
Jun 11, 2020
Merged

refactor: update crypto HOF to Crypto class#36
karrui merged 9 commits intomasterfrom
feat/class-based-crypto

Conversation

@karrui
Copy link
Contributor

@karrui karrui commented Jun 5, 2020

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)

@karrui karrui requested a review from liangyuanruo June 5, 2020 03:56
liangyuanruo
liangyuanruo previously approved these changes Jun 5, 2020
@karrui karrui force-pushed the feat/class-based-crypto branch from f685514 to b62a828 Compare June 8, 2020 04:01
@karrui karrui force-pushed the feat/class-based-subpackages branch from 3d4fcce to 92358d5 Compare June 8, 2020 04:01

if (verifiedContent) {
if (!this.publicSigningKey) {
throw new MissingPublicKeyError(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, should it be the responsibility of the constructor to check such things?

if (err instanceof MissingPublicKeyError) {
throw err
}
return null

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems odd that the caller of this function will not know the cause of the error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an early choice to follow how tweetnacl returns objects. If the encryption failed in anyway, then null is returned.

Base automatically changed from feat/class-based-subpackages to master June 11, 2020 07:11
@karrui karrui dismissed liangyuanruo’s stale review June 11, 2020 07:11

The base branch was changed.

karrui added 9 commits June 11, 2020 15:12
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.
@karrui karrui force-pushed the feat/class-based-crypto branch from b62a828 to 8ce86a5 Compare June 11, 2020 07:13
@karrui karrui requested a review from liangyuanruo June 11, 2020 07:14
@karrui karrui merged commit f0acd09 into master Jun 11, 2020
@karrui karrui deleted the feat/class-based-crypto branch June 11, 2020 07:15
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants