Skip to content

chore: minimally replaces keygrip dep#174

Open
yowainwright wants to merge 2 commits intopillarjs:masterfrom
yowainwright:KOA_ISSUE_1915
Open

chore: minimally replaces keygrip dep#174
yowainwright wants to merge 2 commits intopillarjs:masterfrom
yowainwright:KOA_ISSUE_1915

Conversation

@yowainwright
Copy link
Copy Markdown

Description

This PR is a minimal replacement of keygrip which has been deprecated.

By removing this dep, we fix upstream koa

Thanks!

index.js Outdated
var ah = crypto.createHmac('sha256', key).update(sa).digest()
var bh = crypto.createHmac('sha256', key).update(sb).digest()

return bufferEqual(ah, bh) && a === b
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do we really need a === b at the end when bufferEqual(...) already handled the comparison?

index.js Outdated
function constantTimeCompare (a, b) {
var sa = String(a)
var sb = String(b)
var key = crypto.pseudoRandomBytes(32)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
var key = crypto.pseudoRandomBytes(32)
var key = crypto.randomBytes(32)

Maybe use randomBytes instead?

Comment on lines +309 to +311
if (constantTimeCompare(digest, computed)) {
return i
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Would it be better to check whether crypto.timingSafeEqual(...) is existing and call it here rather than in bufferEqual?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The update, as is, preserves expected node compatibility; adapted from keygrip.
Happy to update along with a node compatibility update if desired!

var http = require('http')
var https = require('https')
var Keygrip = require('keygrip')
var Keygrip = require('..').Keygrip
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We may need this change in other test files that require keygrip.

@ChihweiLHBird
Copy link
Copy Markdown

ChihweiLHBird commented Dec 28, 2025

In addition, we may need an update to the README file about removing/modifying the mentioning of Keygrip.

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.

2 participants