Skip to content

doc: document return values of crypto methods - #66301

Open
BIGSUS24 wants to merge 1 commit into
nodejs:mainfrom
BIGSUS24:doc/crypto-return-values
Open

BIGSUS24 wants to merge 1 commit into
nodejs:mainfrom
BIGSUS24:doc/crypto-return-values

Conversation

@BIGSUS24

Copy link
Copy Markdown
Contributor

Seven crypto methods return the object they were called on, so calls can be chained, but none of them documents a return value:

Method Returns
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() gives Returns: {Hash}, hash.digest() gives Returns: {Buffer | string}, verify.verify() gives Returns: {boolean} — so this is an inconsistency inside crypto.md.

The chaining is worth stating explicitly because hash.copy() also returns {Hash} but returns a new object, whereas hash.update() returns the same instance. The wording says "the Hash object itself" to keep those apart.

How I verified this

Against the source, on current main:

  • lib/internal/crypto/hash.js: Hash.prototype.update ends with return this;, and Hmac.prototype.update = Hash.prototype.update;.
  • lib/internal/crypto/sig.js: Sign.prototype.update ends with return this;, and Verify.prototype.update = Sign.prototype.update;.
  • lib/internal/crypto/diffiehellman.js: DiffieHellman.prototype.setPublicKey and setPrivateKey both end with return this;, and ECDH.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.setPublicKey is wrapped in deprecate()), 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/*.md against lib/ 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.

`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
Copilot AI lite review requested due to automatic review settings September 25, 2026 20:37
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/crypto

@nodejs-github-bot nodejs-github-bot added crypto Issues and PRs related to the crypto subsystem. doc Issues and PRs related to Node.js documentation. labels Sep 25, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 panva left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

just the * Returns: {...} if fine. The prose can go in my opinion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

crypto Issues and PRs related to the crypto subsystem. doc Issues and PRs related to Node.js documentation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants