Skip to content
This repository has been archived by the owner on Mar 5, 2025. It is now read-only.

Commit

Permalink
Merge branch '4.x' into junaid/4xtxwaitfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad-Altabba authored Oct 2, 2023
2 parents 4cadd9b + 4b445ae commit 712ef21
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/web3-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,5 @@ Documentation:

### Changed

- defaultTransactionType is now type 0x2 instead of 0x0 (#6282)
- defaultTransactionType is now type 0x2 instead of 0x0 (#6282)
- Allows formatter to parse large base fee (#6456)
2 changes: 1 addition & 1 deletion packages/web3-core/src/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ export const outputBlockFormatter = (block: BlockInput): BlockOutput => {
}

if (block.baseFeePerGas) {
modifiedBlock.baseFeePerGas = hexToNumber(block.baseFeePerGas);
modifiedBlock.baseFeePerGas = outputBigIntegerFormatter(block.baseFeePerGas);
}

return modifiedBlock;
Expand Down
3 changes: 2 additions & 1 deletion packages/web3-core/test/unit/formatters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,12 +537,13 @@ describe('formatters', () => {
});

it('should convert "baseFeePerGas" from hex to number', () => {
jest.spyOn(formatters, 'outputBigIntegerFormatter').mockReturnValue(123);
const result = outputBlockFormatter({
...validBlock,
baseFeePerGas: 'baseFeePerGas',
} as any);

expect(utils.hexToNumber).toHaveBeenCalledWith('baseFeePerGas');
expect(outputBigIntegerFormatter).toHaveBeenCalledWith('baseFeePerGas');
expect(result).toEqual(expect.objectContaining({ baseFeePerGas: hexToNumberResult }));
});
});
Expand Down
6 changes: 5 additions & 1 deletion packages/web3-eth-accounts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,8 @@ Documentation:
- Fixed "The `r` and `s` returned by `sign` to does not always consist of 64 characters" (#6411)


## [Unreleased]
## [Unreleased]

### Fixed

- Fixed `recover` function, `v` will be normalized to value 0,1 (#6344)
7 changes: 5 additions & 2 deletions packages/web3-eth-accounts/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,13 @@ export const recover = (
const V_INDEX = 130; // r = first 32 bytes, s = second 32 bytes, v = last byte of signature
const hashedMessage = prefixedOrR ? data : hashMessage(data);

const v = signatureOrV.substring(V_INDEX); // 0x + r + s + v
let v = parseInt(signatureOrV.substring(V_INDEX),16); // 0x + r + s + v
if (v > 26) {
v -= 27;
}

const ecPublicKey = secp256k1.Signature.fromCompact(signatureOrV.slice(2, V_INDEX))
.addRecoveryBit(parseInt(v, 16) - 27)
.addRecoveryBit(v)
.recoverPublicKey(hashedMessage.replace('0x', ''))
.toRawBytes(false);

Expand Down
5 changes: 5 additions & 0 deletions packages/web3-eth-accounts/test/fixtures/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,11 @@ export const invalidEncryptData: [
],
];

export const validRecover: [string, string][] = [
[ "I hereby confirm that I am the sole beneficial owner of the assets involved in the business relationship with Fiat24. \nI hereby undertake to inform Fiat24 proactively of any changes to the information contained herein.", "0xec4f73260ac14882e65995a09359896a0ae8f16bd0d28b0d9171655b4e85271e07cda040be059fdcbf52709e3c993eb50a89ce33f41617dc090dc80a583e3c4f00",], // v < 27
["test", "0xefb42c22baa0143b322e93b24b0903a0ef47a64b716fbb77debbea55a93dec3e4417aff7dce845723240916c6e34cf17c674828b3addfb0afad966334df5b6311b"] // v >= 27
]

export const invalidKeyStore: [[any, string]][] = [
[
// invalid keystore error, missing id field
Expand Down
7 changes: 7 additions & 0 deletions packages/web3-eth-accounts/test/unit/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
validHashMessageData,
validPrivateKeytoAccountData,
validPrivateKeyToAddressData,
validRecover,
} from '../fixtures/account';
import { TransactionFactory } from '../../src/tx/transactionFactory';
import { TxData } from '../../src/tx/types';
Expand Down Expand Up @@ -215,5 +216,11 @@ describe('accounts', () => {
await expect(result).rejects.toThrow(Web3ValidatorError);
});
});

describe('valid signatures for recover', () => {
it.each(validRecover)('&s', (data, signature) => {
recover(data, signature)
})
})
});
});

0 comments on commit 712ef21

Please sign in to comment.