Conversation
e317fab to
aab2aee
Compare
c543b15 to
a907f82
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds v4 authentication support to the BitGo SDK, implementing a new HMAC-based authentication scheme that uses newline-separated preimages with body hashing and UUID-based request tracking.
Changes:
- Added v4 authentication support with new HMAC scheme using newline-separated preimage format, seconds-based timestamps, SHA256 body hashing, and UUID request IDs
- Extended type system to support v4 auth including new request/response types, accessTokenId field, and v4-specific request metadata
- Implemented comprehensive test coverage (1000+ lines) covering token lifecycle, request/response verification, backward compatibility, and security edge cases
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| types/superagent/index.d.ts | Added v4 auth metadata fields (v4AuthRequestId, v4Method, v4PathWithQuery) to superagent Request interface |
| modules/sdk-hmac/src/types.ts | Extended AuthVersion type to include version 4 |
| modules/sdk-api/src/types.ts | Exported v4-specific types and added accessTokenId field to BitGoAPIOptions, AccessTokenOptions, and BitGoJson |
| modules/sdk-api/test/unit/v4auth.ts | Comprehensive test suite covering v4 auth lifecycle, request/response verification, HMAC calculation, and backward compatibility |
| modules/sdk-api/src/bitgoAPI.ts | Implemented v4 auth flow including tokenId management, v4 request header generation, and v4 helper methods |
| modules/sdk-api/src/api.ts | Updated response verification to handle v4 auth with proper HMAC and timestamp validation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
9440985 to
1243948
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
1243948 to
a76e4a1
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
arvind-bg
left a comment
There was a problem hiding this comment.
Will there be any impact on the express API responses?
a76e4a1 to
510458a
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
510458a to
fc1ccba
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 8 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
fc1ccba to
9b50b67
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 8 changed files in this pull request and generated 5 comments.
Comments suppressed due to low confidence (1)
modules/sdk-api/src/types.ts:40
- For v4,
requestPatchenforces thataccessTokenandtokenIdare both present, but the public option types still maketokenIdoptional (BitGoAPIOptions.tokenId?andAccessTokenOptions.tokenId?). This mismatch means v4 callers can compile successfully and only fail at runtime. Consider making the types enforce this via a discriminated union onauthVersion(e.g., whenauthVersion: 4, require bothaccessTokenandtokenId).
export interface BitGoAPIOptions {
accessToken?: string;
/** MongoDB _id of the access token. Required for v4 authentication (used as the Bearer value). */
tokenId?: string;
authVersion?: 2 | 3 | 4;
clientConstants?:
| Record<string, any>
| {
constants: Record<string, any>;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
9b50b67 to
4c6d900
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 8 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
4c6d900 to
63dfc7b
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 9 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
63dfc7b to
62c49b5
Compare
62c49b5 to
abb10a6
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Skip the v1 fallback check entirely for v4, since v4 raw tokens may not match v2 format | ||
| if ( | ||
| this._authVersion !== 4 && | ||
| ((this._token && this._token.length !== 67 && this._token.indexOf('v2x') !== 0) || req.forceV1Auth) |
There was a problem hiding this comment.
are we using v2x to identify v4 tokens instead of v4?
There was a problem hiding this comment.
No. We are not using v2x'to identify v4 tokens. The logic is:
1 If authVersion === 4, we skip the above entire v1 fallback check.
2. The v2x check only applies to v2/v3 tokens to decide whether to fall back to v1.
TICKET: CAAS-819
This pull request introduces significant improvements to authentication version handling and response verification in the BitGo Express and SDK-API modules. The main focus is on normalizing and enforcing the
authVersionconfiguration, adding stricter validation and error handling for v4 authentication, and refactoring response HMAC verification logic to be more robust and version-aware. Comprehensive tests have also been added to ensure correct behavior.Authentication version handling and enforcement:
parseAuthVersionfunction to normalizeauthVersionvalues to 2, 3, or 4, defaulting or clamping invalid values to 2, and updated config parsing to use this function. TheConfiginterface now strictly typesauthVersionas2 | 3 | 4. [1] [2] [3] [4]prepareBitGo) to enforce v4 authentication requirements: ifauthVersion=4and an access token is present, theAccess-Key-Idheader must be provided, otherwise the request is rejected with a clear error message. The middleware now passesauthVersionandtokenIdto the SDK. [1] [2] [3]BitGoAPIclass now stores thetokenId(MongoDB ObjectId) for v4 tokens, enabling correct v4 authentication. [1] [2]Response HMAC verification improvements:
verifyResponsefunction in the SDK-API to cleanly separate v2/v3 and v4 logic, using new helpersverifyV4ResponseHeadersandverifyV2V3ResponseHeaders. The v4 logic now strictly requires signature headers on successful responses and provides detailed error context.Testing and validation:
authVersionparsing, covering correct values, clamping of invalid values, precedence of command-line arguments over environment variables, and defaulting behavior.These changes improve security, reliability, and clarity around authentication and response verification for all supported authentication versions.
Authentication version normalization and enforcement
parseAuthVersionto strictly normalize and clampauthVersionto 2, 3, or 4, and updated config parsing and typing to enforce this. [1] [2] [3] [4]Access-Key-Idheader when an access token is present, rejecting non-compliant requests with a clear error. [1] [2] [3]BitGoAPIclass now stores thetokenIdfor v4 tokens, enabling correct v4 authentication. [1] [2]Response verification refactor
verifyResponsein SDK-API to use version-specific helpers for v2/v3 and v4, with stricter enforcement and detailed error context for v4 HMAC verification.Testing
authVersionconfiguration.