feat(auth): bind request payloads into auth proofs#172
Merged
Conversation
… signature, new tests and performance tests
sirdeggen
approved these changes
Jun 10, 2026
- jest.config.js: use String.raw to avoid escaping backslashes in regex - authProof.perf.test.ts: import from 'node:perf_hooks' for consistency Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
|
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.



Summary
@bsv/authis documented as authenticating requests, butcreateAuthProof/verifyAuthProofonly ever signed{ action, identityKey, expiresAt, nonce }. Therewas no way to bind a request's payload, so for any action that carries a body (e.g. a
username change →
{ newUsername }) the body was not covered by the signature — anintermediary could alter it and the proof still verified. This PR closes that gap by
letting a proof optionally bind the request body, and tidies the now-too-long parameter
list into a named-args object.
What changed
createAuthProofandverifyAuthProofaccept anoptional
body. The client signs over the auth fields plus the body bytes; theverifier binds the raw received body the same way. A tampered, missing, or injected
body fails the signature check. The body is bound only — it is not added to
proof.dataand is transmitted with the request as usual.(VarInt length + bytes via
Utils.Writer), so arbitrary binary is unambiguous. Withno body the signed bytes are exactly
serializeAuthSigData(data)as before.normalizeBody):string→ UTF-8,ArrayBuffer/ typedarray → raw bytes, plain object or any array → JSON. Binary must be passed as a typed
array /
ArrayBuffer; arrays are always treated as structured data.CreateAuthProofArgs/VerifyAuthProofArgs, both extendingAuthProofOptions), matching the@bsv/sdkwallet-method style and removing the fragile 5-positional-arg ordering. The
AuthProofClient/AuthProofServerwrappers take the same object minus the boundoptions.
npm run test:perf(dedicatedjest.perf.config.js,excluded from the default run) measuring create/verify vs. the pure serialization
functions.
Why
The lightweight signed-proof scheme is meant to authenticate any single request, not
just login. Authenticating the action but not the body is a real integrity gap for
any write request. Length-prefixed binding is the minimal, transport-agnostic way to
cover the payload (same approach as
AuthFetch's request serialization) withoutchanging the proof's shape or its single-use / expiry semantics.
Why this fixes the issue
A body-bearing request signed via
createAuthProof({ …, body })and verified viaverifyAuthProof({ …, body })now fails verification if the body differs by a singlebyte — so the proof genuinely authenticates the request contents the docs promised, not
just the action. Login and other bodyless calls are unaffected.
Backward compatibility
bodyproduces byte-identical signed bytes to the previous version, soexisting bodyless (login) proofs verify unchanged.
(
expectedAction→action); this is the one breaking change. Downstream callerswere updated in tandem.
Testing
npm test— full unit + real-ProtoWalletround-trip suite (same-body verifies;tampered / missing / injected / binary bodies behave correctly; login unchanged).
npm run test:perf— confirms body binding adds ~12 µs over a ~5 ms signing op(≈0.2%), i.e. no measurable overhead.