Conversation
`hash.update()`, `hmac.update()`, `sign.update()`, `verify.update()`, `diffieHellman.setPrivateKey()`, `diffieHellman.setPublicKey()` and `ecdh.setPrivateKey()` all return the object they were called on, so calls can be chained, but none of them documents a return value. Sibling methods in the same sections, such as `hash.copy()`, `hash.digest()` and `verify.verify()`, already document theirs. Verified against lib/internal/crypto/hash.js, sig.js and diffiehellman.js, where each of these returns `this`; `Hmac.prototype.update` and `Verify.prototype.update` are aliases of the `Hash` and `Sign` versions, and `ECDH.prototype.setPrivateKey` is an alias of the `DiffieHellman` version. Also verified at runtime on v22.14.0 that each call returns the receiving object. `ecdh.setPublicKey()` returns the same way but is left undocumented here because it is deprecated. Signed-off-by: BIGSUS24 <152616194+BIGSUS24@users.noreply.github.com> Assisted-by: a closed-source coding agent
Collaborator
|
Review requested:
|
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
Documentation changes align the API reference with implementation behavior, with no unresolved issues.
Review effort: Lite
Findings: None
What changed in this PR
Documents return values for seven chainable crypto methods.
Changes:
- Adds return annotations for hash, HMAC, signing, and verification updates.
- Documents return values for Diffie-Hellman and ECDH setters.
- Clarifies that methods return the same object instance.
| File | Description |
|---|---|
doc/api/crypto.md |
Documents the objects returned by seven methods. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
panva
reviewed
Sep 25, 2026
panva
left a comment
Member
There was a problem hiding this comment.
just the * Returns: {...} if fine. The prose can go in my opinion.
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.
Seven
cryptomethods return the object they were called on, so calls can be chained, but none of them documents a return value:hash.update(){Hash}hmac.update(){Hmac}sign.update(){Sign}verify.update(){Verify}diffieHellman.setPrivateKey(){DiffieHellman}diffieHellman.setPublicKey(){DiffieHellman}ecdh.setPrivateKey(){ECDH}Sibling methods in the same sections already document theirs —
hash.copy()givesReturns: {Hash},hash.digest()givesReturns: {Buffer | string},verify.verify()givesReturns: {boolean}— so this is an inconsistency insidecrypto.md.The chaining is worth stating explicitly because
hash.copy()also returns{Hash}but returns a new object, whereashash.update()returns the same instance. The wording says "theHashobject itself" to keep those apart.How I verified this
Against the source, on current
main:lib/internal/crypto/hash.js:Hash.prototype.updateends withreturn this;, andHmac.prototype.update = Hash.prototype.update;.lib/internal/crypto/sig.js:Sign.prototype.updateends withreturn this;, andVerify.prototype.update = Sign.prototype.update;.lib/internal/crypto/diffiehellman.js:DiffieHellman.prototype.setPublicKeyandsetPrivateKeyboth end withreturn this;, andECDH.prototype.setPrivateKey = DiffieHellman.prototype.setPrivateKey;.At runtime on v22.14.0, each of the seven calls returned the receiving object (
assert.strictEqual(obj.method(...), obj)passed for all seven).Not included
ecdh.setPublicKey()behaves the same way, but it's deprecated (ECDH.prototype.setPublicKeyis wrapped indeprecate()), so I'd rather not add new detail to it. Say the word if you'd like it documented too.Disclosure per AGENTS.md: I used a coding agent (Claude Code) to scan
doc/api/*.mdagainstlib/for documented methods with undocumented return values. I read each hit in the source myself and ran the runtime checks above before opening this; the exclusions above are my own call.