Skip to content

Conversation

parvaparikh-30
Copy link

@parvaparikh-30 parvaparikh-30 commented Sep 18, 2025

One of the client was using Bitgo Express to sign DvP settlements
This API Helps them to retrieve payload in json string
In docs, its mentioned that using /api/v2/ofc/signPayload users would be able to create signature & then sign a settlement
While debugging found that, the already stringified payload (body) gets stringified again(backend) which mess up the signature & thus client is getting error - Signature Verification Failed
More context - slack thread
Fix:
Validate if the payload in req is already stringified or not, if yes then ignore else stringify it
Added test cases to confirm its working

Logic - Screenshot 2025-09-18 at 3 06 54 PM

Test Cases Verfifcation -
Screenshot 2025-09-18 at 3 06 22 PM

Ticket: GNA-2162

});
it('should return a signed payload with type as json string', async function () {
// TODO(GO-1015): unskip test
return;

Choose a reason for hiding this comment

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

Why are we skipping this test?

Copy link
Author

Choose a reason for hiding this comment

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

https://bitgoinc.atlassian.net/browse/GO-1015
Its causing some problem in CI, it was already defined so kept it as it is
But ran locally, which ran perfectly, you can find it in description

Copy link
Contributor

Choose a reason for hiding this comment

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

Its causing some problem in CI,
But ran locally, which ran perfectly,

This is not an acceptable approach. Please fix the failing test.

Copy link
Contributor

Choose a reason for hiding this comment

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

If the test failure is consistent, that points to this PR as the cause.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks Zahin for the feedback, it was from different team so kept the same
But I will look into the issue & rectify it

@@ -630,7 +639,7 @@ export async function handleV2OFCSignPayload(req: express.Request): Promise<{ pa

const walletPassphrase = bodyWalletPassphrase || getWalletPwFromEnv(wallet.id());
const tradingAccount = wallet.toTradingAccount();
const stringifiedPayload = JSON.stringify(req.body.payload);
const stringifiedPayload = isJsonString(req.body.payload) ? req.body.payload : JSON.stringify(req.body.payload);
Copy link
Contributor

Choose a reason for hiding this comment

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

As a follow up, please consider migrating this api to an api-ts typed route! This way you can define your input codec and have your input validation done automatically!

Copy link
Contributor

Choose a reason for hiding this comment

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

io-ts and io-ts-types already have codecs for json and json strings.

});
it('should return a signed payload with type as json string', async function () {
// TODO(GO-1015): unskip test
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

Its causing some problem in CI,
But ran locally, which ran perfectly,

This is not an acceptable approach. Please fix the failing test.

});
it('should return a signed payload with type as json string', async function () {
// TODO(GO-1015): unskip test
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

If the test failure is consistent, that points to this PR as the cause.

@@ -589,6 +589,15 @@ export async function handleV2OFCSignPayloadInExtSigningMode(
}
}

const isJsonString = (str: any): boolean => {
Copy link
Contributor

@mmcshinsky-bitgo mmcshinsky-bitgo Sep 19, 2025

Choose a reason for hiding this comment

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

Can we move one-off functions like this out to a util file? clientRoutes is huge as it is already 😭

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.

4 participants