Skip to content

Commit

Permalink
6004 replace buffer with uint8array (#6033)
Browse files Browse the repository at this point in the history
* fix: remove Buffer from web3-validator

* fixed unit tests
Signed-off-by: Marin Petrunic <marin.petrunic@gmail.com>

Signed-off-by: Marin Petrunic <marin.petrunic@gmail.com>

* replace buffer

* fix unit tests

* update method

* debug

* update converters

* update keccakwrapper

* fix build error

* update eslint

* update eslint

* update changelog

* address feedback and changing buffer to uint8

* add uint8array tests

* adding uint8array tests

* update fixtures

* update bytestobuffer to bytestouint8array

* removing FMT_BYTES.BUFFER

* replace buffer with uint8array in e2e web3 tests

* update buffer to uint8array

* replacing buffer to uint8array test fixture

* replace buffer with uint8array in tx web3-eth-accounts

* replace buffer with uint8array web3-eth web3-utils

* update doc examples and tests

* update asciiToHex function

* refactor

* adding testcases

* debug

* debug

* remove debugs

---------

Signed-off-by: Marin Petrunic <marin.petrunic@gmail.com>
Co-authored-by: Marin Petrunic <marin.petrunic@gmail.com>
Co-authored-by: Muhammad Altabba <24407834+Muhammad-Altabba@users.noreply.github.com>
Co-authored-by: Junaid <86780488+jdevcs@users.noreply.github.com>
  • Loading branch information
4 people authored May 3, 2023
1 parent 7c13a90 commit 47abef0
Show file tree
Hide file tree
Showing 132 changed files with 1,530 additions and 1,338 deletions.
4 changes: 4 additions & 0 deletions packages/web3-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `getConfig` method from `Web3Config` class, `config` is now public and accessible using `Web3Config.config` (#5950)

## [Unreleased]

### Changed

- Replaced Buffer for Uint8Array (#6004)
2 changes: 1 addition & 1 deletion packages/web3-core/src/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import { isBlockTag, isHex, isNullish } from 'web3-validator';
* @deprecated Use format function from web3-utils package instead
* Will format the given storage key array values to hex strings.
*/
export const inputStorageKeysFormatter = (keys: Array<string>) => keys.map(numberToHex);
export const inputStorageKeysFormatter = (keys: Array<string>) => keys.map(num => numberToHex(num));

/**
* @deprecated Use format function from web3-utils package instead
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-core/src/web3_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ export type TransactionBuilder<API extends Web3APISpec = unknown> = <
>(options: {
transaction: Transaction;
web3Context: Web3Context<API>;
privateKey?: HexString | Buffer;
privateKey?: HexString | Uint8Array;
}) => Promise<ReturnType>;

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-errors/src/errors/account_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class PrivateKeyLengthError extends BaseWeb3Error {
export class InvalidPrivateKeyError extends BaseWeb3Error {
public code = ERR_INVALID_PRIVATE_KEY;
public constructor() {
super(`Invalid Private Key, Not a valid string or buffer`);
super(`Invalid Private Key, Not a valid string or uint8Array`);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-abi/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export const formatParam = (type: string, _param: unknown): unknown => {
// Format correct length for bytes[0-9]+
match = paramTypeBytes.exec(type);
if (match) {
const hexParam = Buffer.isBuffer(param) ? toHex(param) : param;
const hexParam = param instanceof Uint8Array ? toHex(param) : param;

// format to correct length
const size = parseInt(match[1], 10);
Expand Down
6 changes: 6 additions & 0 deletions packages/web3-eth-accounts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- The method `signTransaction` returned by `privateKeyToAccount` is now accepting the type `Transaction` for its argument. (#5993)

## [Unreleased]

### Changed

- Replaced `Buffer` for `Uint8Array` (#6004)
- The methods `recover`, `encrypt`, `privateKeyToAddress` does not support type `Buffer` but supports type `Uint8Array` (#6004)
- The method `parseAndValidatePrivateKey` returns a type `Uint8Array` instead of type `Buffer` (#6004)
Loading

0 comments on commit 47abef0

Please sign in to comment.