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

Commit 31d3eea

Browse files
authored
Merge pull request #2794 from ethereum/issue/1490
randomHex fixed
2 parents 9fce68d + 334c2b5 commit 31d3eea

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

packages/web3-utils/package-lock.json

Lines changed: 12 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/web3-utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"ethjs-unit": "^0.1.6",
2525
"lodash": "^4.17.11",
2626
"number-to-bn": "1.7.0",
27-
"randomhex": "0.1.5",
27+
"randombytes": "^2.1.0",
2828
"utf8": "2.1.1"
2929
},
3030
"devDependencies": {

packages/web3-utils/src/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,21 @@ import isArray from 'lodash/isArray';
2727
import * as utils from './Utils';
2828
import * as ethjsUnit from 'ethjs-unit';
2929
import Hash from 'eth-lib/lib/hash';
30+
import randombytes from 'randombytes';
3031

3132
export BN from 'bn.js';
3233
export {soliditySha3} from './SoliditySha3';
33-
export randomHex from 'randomhex';
34+
35+
/**
36+
* Returns a random hex string by the given bytes size
37+
*
38+
* @param {Number} size
39+
*
40+
* @returns {string}
41+
*/
42+
export const randomHex = (size) => {
43+
return '0x' + randombytes(size).toString('hex');
44+
};
3445

3546
/**
3647
* Should be used to create full function/event name from json abi

0 commit comments

Comments
 (0)