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

Commit 4524ea0

Browse files
Update sha3 and sha3Raw type definitions to accept Buffer (#5357)
* Update sha3 type def to accept Buffer
1 parent 9f4e7c0 commit 4524ea0

File tree

5 files changed

+12
-5
lines changed

5 files changed

+12
-5
lines changed

CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -586,4 +586,7 @@ Released with 1.0.0-beta.37 code base.
586586

587587
## [Unreleased]
588588

589-
## [1.7.6]
589+
## [1.7.6]
590+
591+
### Changed
592+
- Updated `sha3` and `sha3Raw` type definition to accept `Buffer`

docs/web3-utils.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ sha3
218218

219219
.. code-block:: javascript
220220
221-
web3.utils.sha3(string)
222-
web3.utils.keccak256(string) // ALIAS
221+
web3.utils.sha3(string | BN | Buffer)
222+
web3.utils.keccak256(string | BN | Buffer) // ALIAS
223223
224224
Will calculate the sha3 of the input.
225225

packages/web3-utils/types/index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ export function padLeft(value: string | number, characterAmount: number, sign?:
9595
export function leftPad(string: string | number, characterAmount: number, sign?: string): string;
9696
export function rightPad(string: string | number, characterAmount: number, sign?: string): string;
9797
export function padRight(string: string | number, characterAmount: number, sign?: string): string;
98-
export function sha3(value: string | BN): string | null;
99-
export function sha3Raw(value: string | BN): string;
98+
export function sha3(value: string | BN | Buffer): string | null;
99+
export function sha3Raw(value: string | BN | Buffer): string;
100100
export function randomHex(bytesSize: number): string;
101101
export function utf8ToHex(string: string): string;
102102
export function stringToHex(string: string): string;

packages/web3-utils/types/tests/sha3-raw-test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import {sha3Raw} from 'web3-utils';
2626
// $ExpectType string
2727
sha3Raw('234');
2828
// $ExpectType string
29+
sha3Raw(Buffer.from('123'));
30+
// $ExpectType string
2931
sha3Raw(new BN(3));
3032

3133
// $ExpectError

packages/web3-utils/types/tests/sha3-test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import {sha3} from 'web3-utils';
2626
// $ExpectType string | null
2727
sha3('234');
2828
// $ExpectType string | null
29+
sha3(Buffer.from('123'));
30+
// $ExpectType string | null
2931
sha3(new BN(3));
3032

3133
// $ExpectError

0 commit comments

Comments
 (0)