diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-05-25 17:19:14 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-05-25 17:19:14 +0800 |
commit | 55c491f8ea8bb0ba8cb1b856b3c42dd05c31565d (patch) | |
tree | 94dbab4d33f03f1b1299bd9e6326bdc6dabcc83b /src | |
parent | d23dbf53fd3689613f28d576d03ccfdce94b6646 (diff) | |
download | dexon-sol-tools-55c491f8ea8bb0ba8cb1b856b3c42dd05c31565d.tar dexon-sol-tools-55c491f8ea8bb0ba8cb1b856b3c42dd05c31565d.tar.gz dexon-sol-tools-55c491f8ea8bb0ba8cb1b856b3c42dd05c31565d.tar.bz2 dexon-sol-tools-55c491f8ea8bb0ba8cb1b856b3c42dd05c31565d.tar.lz dexon-sol-tools-55c491f8ea8bb0ba8cb1b856b3c42dd05c31565d.tar.xz dexon-sol-tools-55c491f8ea8bb0ba8cb1b856b3c42dd05c31565d.tar.zst dexon-sol-tools-55c491f8ea8bb0ba8cb1b856b3c42dd05c31565d.zip |
Add generateSalt and tests for it
Diffstat (limited to 'src')
-rw-r--r-- | src/ts/0x.js.ts | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/ts/0x.js.ts b/src/ts/0x.js.ts index acbdd01e2..14f9f2061 100644 --- a/src/ts/0x.js.ts +++ b/src/ts/0x.js.ts @@ -11,6 +11,8 @@ export interface ECSignature { s: string; } +const MAX_DIGITS_IN_UNSIGNED_256_INT = 78; + export class ZeroEx { /** * Verifies that the elliptic curve signature `signature` was generated @@ -34,4 +36,13 @@ export class ZeroEx { return false; } } + /** Generates pseudo-random 256 bits salt */ + public static generatePseudoRandomSalt(): BigNumber.BigNumber { + // BigNumber.random returns a pseudo-random number between 0 & 1 with a passed in number of decimal places. + // Source: https://mikemcl.github.io/bignumber.js/#random + const randomNumber = BigNumber.random(MAX_DIGITS_IN_UNSIGNED_256_INT); + const factor = new BigNumber(10).pow(MAX_DIGITS_IN_UNSIGNED_256_INT - 1); + const salt = randomNumber.times(factor).round(); + return salt; + } } |