aboutsummaryrefslogtreecommitdiffstats
path: root/src/ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-05-25 18:11:12 +0800
committerFabio Berger <me@fabioberger.com>2017-05-25 18:11:12 +0800
commitec2d3cc599e4b2b48669983f090b29581ba6f25d (patch)
tree1dd0dc0e8dc972bf969a3a1e9447fbc3af9ca63d /src/ts
parent56dfe6b2ff4a5ee7f5dd6c721f2e1cc9d6358998 (diff)
parent334d2f175fd9dcb3f9e336250d21c7916a2671ae (diff)
downloaddexon-sol-tools-ec2d3cc599e4b2b48669983f090b29581ba6f25d.tar
dexon-sol-tools-ec2d3cc599e4b2b48669983f090b29581ba6f25d.tar.gz
dexon-sol-tools-ec2d3cc599e4b2b48669983f090b29581ba6f25d.tar.bz2
dexon-sol-tools-ec2d3cc599e4b2b48669983f090b29581ba6f25d.tar.lz
dexon-sol-tools-ec2d3cc599e4b2b48669983f090b29581ba6f25d.tar.xz
dexon-sol-tools-ec2d3cc599e4b2b48669983f090b29581ba6f25d.tar.zst
dexon-sol-tools-ec2d3cc599e4b2b48669983f090b29581ba6f25d.zip
Merge branch 'master' into addSchemas
# Conflicts: # package.json
Diffstat (limited to 'src/ts')
-rw-r--r--src/ts/0x.js.ts15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/ts/0x.js.ts b/src/ts/0x.js.ts
index 8de87e96e..1cc2d8b44 100644
--- a/src/ts/0x.js.ts
+++ b/src/ts/0x.js.ts
@@ -12,6 +12,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
@@ -35,4 +37,17 @@ export class ZeroEx {
return false;
}
}
+ /**
+ * Generates pseudo-random 256 bit salt.
+ * The salt is used to ensure that the 0x order generated has a unique orderHash that does
+ * not collide with any other outstanding orders.
+ */
+ 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;
+ }
}