aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils/src/address_utils.ts
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2019-02-09 08:04:45 +0800
committerGreg Hysen <greg.hysen@gmail.com>2019-02-09 09:12:58 +0800
commita9aaae7f97b2684107d158db0c1530749e096b3e (patch)
tree83021552be3b885c1d3ea512007edeaae09d136d /packages/utils/src/address_utils.ts
parent500b4940a320c842394c996f15495c1cdc7b3547 (diff)
downloaddexon-0x-contracts-a9aaae7f97b2684107d158db0c1530749e096b3e.tar.gz
dexon-0x-contracts-a9aaae7f97b2684107d158db0c1530749e096b3e.tar.zst
dexon-0x-contracts-a9aaae7f97b2684107d158db0c1530749e096b3e.zip
Deduped random value generation from salt generation
Diffstat (limited to 'packages/utils/src/address_utils.ts')
-rw-r--r--packages/utils/src/address_utils.ts11
1 files changed, 10 insertions, 1 deletions
diff --git a/packages/utils/src/address_utils.ts b/packages/utils/src/address_utils.ts
index 1fc960408..361e35cd8 100644
--- a/packages/utils/src/address_utils.ts
+++ b/packages/utils/src/address_utils.ts
@@ -1,7 +1,9 @@
-import { addHexPrefix, stripHexPrefix } from 'ethereumjs-util';
+import { addHexPrefix, sha3, stripHexPrefix } from 'ethereumjs-util';
import * as jsSHA3 from 'js-sha3';
import * as _ from 'lodash';
+import { generatePseudoRandom256BitNumber } from './random';
+
const BASIC_ADDRESS_REGEX = /^(0x)?[0-9a-f]{40}$/i;
const SAME_CASE_ADDRESS_REGEX = /^(0x)?([0-9a-f]{40}|[0-9A-F]{40})$/;
const ADDRESS_LENGTH = 40;
@@ -43,4 +45,11 @@ export const addressUtils = {
padZeros(address: string): string {
return addHexPrefix(_.padStart(stripHexPrefix(address), ADDRESS_LENGTH, '0'));
},
+ generatePseudoRandomAddress(): string {
+ const randomBigNum = generatePseudoRandom256BitNumber();
+ const randomBuff = sha3(randomBigNum.toString());
+ const addressLengthInBytes = 20;
+ const randomAddress = `0x${randomBuff.slice(0, addressLengthInBytes).toString('hex')}`;
+ return randomAddress;
+ },
};