Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert Buffer and node crypto to web apis #11

Merged
merged 1 commit into from
Sep 8, 2024

Conversation

bitofbreeze
Copy link
Contributor

This PR converts all uses of Buffer and node crypto APIs to Uint8array and web crypto.

This would be a major release because it bumps the minimum node engine version and converts all exports to be async.

This makes this package fully compatibility with serverless, and would make remix-auth-totp too dev-xo/remix-auth-totp#74

If this isn't desired, I can make a new package.

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

Thanks for this. I'm a fan. Bummer it makes this async and will require a major version bump, but it's fine.

@kentcdodds kentcdodds merged commit e4b8a20 into epicweb-dev:main Sep 8, 2024
2 checks passed
Copy link

github-actions bot commented Sep 8, 2024

🎉 This PR is included in version 2.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

chrisvariety added a commit to chrisvariety/totp that referenced this pull request Sep 10, 2024
Now that epicweb-dev#11 has landed, the README needs to be updated to reflect the new `async` functions.
@@ -11,7 +9,7 @@ import base32Decode from 'base32-decode'
// That said, if you're acting the role of both client and server and your TOTP
// is longer lived, you can definitely use a more secure algorithm like SHA256.
// Learn more: https://www.rfc-editor.org/rfc/rfc4226#page-25 (B.1. SHA-1 Status)
const DEFAULT_ALGORITHM = 'SHA1'
const DEFAULT_ALGORITHM = 'SHA-1'
Copy link
Member

Choose a reason for hiding this comment

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

Can you help me understand why it was important to change these algorithm names? OTP clients break when you include the hyphen:

image

cc @dev-xo have you seen issues with this change?

Copy link
Member

Choose a reason for hiding this comment

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

For now I'm just planning on doing this:

const otpUri = getTOTPAuthUri({
	...verification,
	// OTP clients break with the `-` in the algorithm name.
	algorithm: verification.algorithm.replaceAll('-', ''),
	accountName: user.email,
	issuer,
})

But the other thing is this change necessitates a data migration if people saved the algorithm in the database and that kinda stinks. Would rather revert this change if it's not actually important.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

web crypto apis use this spelling

Copy link

@dev-xo dev-xo Oct 20, 2024

Choose a reason for hiding this comment

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

No idea @kentcdodds (also no issues found for us).

I think the same changes were applied for remix-auth-totp if I'm not wrong, although the Strategy does not store the algorithm in the database, so probably those refactors were a bit safer for us.

Feel free to take the changes/actions you think @epic-web/totp may require Kent, as those probably do not affect us, and if does, we can adapt the Strategy to those.


A question I have for @bitofbreeze: Do you know if SHA1 and SHA-1 (with hyphen) are the same, or if the algorithm is recognized in both formats?

Copy link
Contributor Author

@bitofbreeze bitofbreeze Oct 21, 2024

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants