Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure r and s returned by signTransaction to have 64 character #6216

Merged
merged 3 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/web3-eth-accounts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,7 @@ Documentation:
[Migration Guide from 1.x](https://docs.web3js.org/guides/web3_upgrade_guide/x/)

## [Unreleased]

### Fixed

- Fixed "The `r` and `s` returned by `signTransaction` to does not always consist of 64 characters #6207" (#6216)
4 changes: 2 additions & 2 deletions packages/web3-eth-accounts/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ export const signTransaction = async (
return {
messageHash: bytesToHex(signedTx.getMessageToSign(true)),
v: `0x${signedTx.v.toString(16)}`,
r: `0x${signedTx.r.toString(16)}`,
s: `0x${signedTx.s.toString(16)}`,
r: `0x${signedTx.r.toString(16).padStart(64, '0')}`,
s: `0x${signedTx.s.toString(16).padStart(64, '0')}`,
rawTransaction: rawTx,
transactionHash: bytesToHex(txHash),
};
Expand Down
6 changes: 3 additions & 3 deletions packages/web3-eth-accounts/test/unit/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ describe('accounts', () => {
expect(signedResult.messageHash).toBeDefined();
expect(signedResult.rawTransaction).toBeDefined();
expect(signedResult.transactionHash).toBeDefined();
expect(signedResult.r).toBeDefined();
expect(signedResult.s).toBeDefined();
expect(signedResult.v).toBeDefined();
expect(signedResult.r).toMatch(/0[xX][0-9a-fA-F]{64}/);
expect(signedResult.s).toMatch(/0[xX][0-9a-fA-F]{64}/);
expect(signedResult.v).toMatch(/0[xX][0-9a-fA-F]+/);
});

it.each(transactionsTestData)('Recover transaction', async txData => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ describe('Web3Eth.signTransaction', () => {
// Pulling out of toMatchObject to be compatiable with Cypress
expect(response.raw).toMatch(/0[xX][0-9a-fA-F]+/);
expect(typeof (response.tx as TransactionLegacySignedAPI).v).toBe('bigint');
expect(response.tx.r).toMatch(/0[xX][0-9a-fA-F]+/);
expect(response.tx.s).toMatch(/0[xX][0-9a-fA-F]+/);
expect(response.tx.r).toMatch(/0[xX][0-9a-fA-F]{64}/);
expect(response.tx.s).toMatch(/0[xX][0-9a-fA-F]{64}/);
});

it('should sign a contract deployment', async () => {
Expand Down Expand Up @@ -90,7 +90,7 @@ describe('Web3Eth.signTransaction', () => {
// Pulling out of toMatchObject to be compatiable with Cypress
expect(response.raw).toMatch(/0[xX][0-9a-fA-F]+/);
expect(typeof (response.tx as TransactionLegacySignedAPI).v).toBe('bigint');
expect(response.tx.r).toMatch(/0[xX][0-9a-fA-F]+/);
expect(response.tx.s).toMatch(/0[xX][0-9a-fA-F]+/);
expect(response.tx.r).toMatch(/0[xX][0-9a-fA-F]{64}/);
expect(response.tx.s).toMatch(/0[xX][0-9a-fA-F]{64}/);
});
});