mirror of https://github.com/status-im/web3.js.git
added randomeHex to utils
This commit is contained in:
parent
5e24628dbd
commit
f731cc5021
|
@ -44,6 +44,13 @@ Example
|
|||
|
||||
.. code-block:: javascript
|
||||
|
||||
web3.eth.accounts.generate();
|
||||
> {
|
||||
address: "0xb8CE9ab6943e0eCED004cDe8e3bBed6568B2Fa01",
|
||||
publicKey: "0xbb1846722a4c27e71196e1a44611ee7174276a6c51c4830fb810cac64b0725f217cb8783625a809d1303adeeec2cf036ab74098a77a6b7f1003486e173b29aa7"
|
||||
privateKey: "0x348ce564d427a3311b6536bbcff9390d69395b06ed6c486954e971d960fe8709",
|
||||
}
|
||||
|
||||
web3.eth.accounts.generate('2435@#@#@±±±±!!!!678543213456764321§34567543213456785432134567');
|
||||
> {
|
||||
address: "0xF2CD2AA0c7926743B1D4310b2BC984a0a453c3d4",
|
||||
|
@ -51,11 +58,11 @@ Example
|
|||
privateKey: "0xd7325de5c2c1cf0009fac77d3d04a9c004b038883446b065871bc3e831dcd098",
|
||||
}
|
||||
|
||||
web3.eth.accounts.generate();
|
||||
web3.eth.accounts.generate(web3.utils.randomHex(32));
|
||||
> {
|
||||
address: "0xb8CE9ab6943e0eCED004cDe8e3bBed6568B2Fa01",
|
||||
publicKey: "0xbb1846722a4c27e71196e1a44611ee7174276a6c51c4830fb810cac64b0725f217cb8783625a809d1303adeeec2cf036ab74098a77a6b7f1003486e173b29aa7"
|
||||
privateKey: "0x348ce564d427a3311b6536bbcff9390d69395b06ed6c486954e971d960fe8709",
|
||||
address: "0xe78150FaCD36E8EB00291e251424a0515AA1FF05",
|
||||
publicKey: "0x03ade6efb5848276b2ed4185f2523fabaec2443c42c5f648ca3a419d5234dcd03ee22333104be64df1b6db1536591b00cd425b7e13d45c75cea857cf1d4861f7"
|
||||
privateKey: "0xcc505ee6067fba3f6fc2050643379e190e087aeffe5d958ab9f2f3ed3800fa4e",
|
||||
}
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
|
|
@ -6,6 +6,53 @@ web3.utils
|
|||
|
||||
This package provides utility functions for Ethereum dapps and other web3.js packages.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
randomHex
|
||||
=====================
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
web3.utils.randomHex(size)
|
||||
|
||||
The `randomHex <https://github.com/frozeman/randomHex`_ library to generate cryptographically strong pseudo-random HEX strings from a given byte size.
|
||||
|
||||
----------
|
||||
Parameters
|
||||
----------
|
||||
|
||||
1. ``size`` - ``Number``: The byte size for the HEX string, e.g. ``32`` will result in a 32 bytes HEX string with 64 characters preficed with "0x".
|
||||
|
||||
-------
|
||||
Returns
|
||||
-------
|
||||
|
||||
``String``: The generated random HEX string.
|
||||
|
||||
-------
|
||||
Example
|
||||
-------
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
web3.utils.randomHex(32)
|
||||
> "0xa5b9d60f32436310afebcfda832817a68921beb782fabf7915cc0460b443116a"
|
||||
|
||||
web3.utils.randomHex(4)
|
||||
> "0x6892ffc6"
|
||||
|
||||
web3.utils.randomHex(2)
|
||||
> "0x99d6"
|
||||
|
||||
web3.utils.randomHex(1)
|
||||
> "0x9a"
|
||||
|
||||
web3.utils.randomHex(0)
|
||||
> "0x"
|
||||
|
||||
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
_
|
||||
|
@ -35,8 +82,6 @@ Example
|
|||
...
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
"web3-net": "^1.0.0",
|
||||
"web3-utils": "^1.0.0",
|
||||
"ethjs-account": "^0.1.0",
|
||||
"randomhex": "^0.1.5",
|
||||
"underscore": "^1.8.3"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var randomhex = require('randomhex');
|
||||
var utils = require('web3-utils');
|
||||
var accounts = require('ethjs-account');
|
||||
|
||||
|
||||
|
@ -30,7 +30,7 @@ var accounts = require('ethjs-account');
|
|||
module.exports = {
|
||||
generate: function generate(randomString) {
|
||||
if(!randomString) {
|
||||
randomString = randomhex(32);
|
||||
randomString = utils.randomHex(32);
|
||||
}
|
||||
return accounts.generate(randomString);
|
||||
},
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
"dependencies": {
|
||||
"utf8": "^2.1.1",
|
||||
"underscore": "^1.8.3",
|
||||
|
||||
"randomhex": "^0.1.5",
|
||||
"js-sha3": "^0.5.7",
|
||||
"ethjs-unit": "^0.1.6",
|
||||
"number-to-bn": "^1.7.0",
|
||||
|
|
|
@ -26,6 +26,8 @@ var _ = require('underscore');
|
|||
var ethjsUnit = require('ethjs-unit');
|
||||
var utils = require('./utils.js');
|
||||
var soliditySha3 = require('./soliditySha3.js');
|
||||
var randomHex = require('randomhex');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
@ -249,6 +251,7 @@ module.exports = {
|
|||
_jsonInterfaceMethodToString: _jsonInterfaceMethodToString,
|
||||
// extractDisplayName: extractDisplayName,
|
||||
// extractTypeName: extractTypeName,
|
||||
randomHex: randomHex,
|
||||
_: _,
|
||||
BN: utils.BN,
|
||||
isBN: utils.isBN,
|
||||
|
|
Loading…
Reference in New Issue