aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-utils/src
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-07-12 21:53:31 +0800
committerGitHub <noreply@github.com>2018-07-12 21:53:31 +0800
commita45a29432e722b71fcfc63a8545fa43ffc29b92d (patch)
tree84fbd6c8d1fb87fd1e36dabd808ce897e346ff8c /packages/order-utils/src
parent34a903516439ec64073cfcb10cee87a9c4db902e (diff)
parent819d069edc6ff31f8f08231b5087b125b872cf97 (diff)
downloaddexon-sol-tools-a45a29432e722b71fcfc63a8545fa43ffc29b92d.tar
dexon-sol-tools-a45a29432e722b71fcfc63a8545fa43ffc29b92d.tar.gz
dexon-sol-tools-a45a29432e722b71fcfc63a8545fa43ffc29b92d.tar.bz2
dexon-sol-tools-a45a29432e722b71fcfc63a8545fa43ffc29b92d.tar.lz
dexon-sol-tools-a45a29432e722b71fcfc63a8545fa43ffc29b92d.tar.xz
dexon-sol-tools-a45a29432e722b71fcfc63a8545fa43ffc29b92d.tar.zst
dexon-sol-tools-a45a29432e722b71fcfc63a8545fa43ffc29b92d.zip
Merge pull request #863 from 0xProject/refactor/0x.js
Refactor 0x.js
Diffstat (limited to 'packages/order-utils/src')
-rw-r--r--packages/order-utils/src/signature_utils.ts20
1 files changed, 20 insertions, 0 deletions
diff --git a/packages/order-utils/src/signature_utils.ts b/packages/order-utils/src/signature_utils.ts
index d8703bfda..26fb24705 100644
--- a/packages/order-utils/src/signature_utils.ts
+++ b/packages/order-utils/src/signature_utils.ts
@@ -27,6 +27,10 @@ export async function isValidSignatureAsync(
signature: string,
signerAddress: string,
): Promise<boolean> {
+ assert.isWeb3Provider('provider', provider);
+ assert.isHexString('data', data);
+ assert.isHexString('signature', signature);
+ assert.isETHAddressHex('signerAddress', signerAddress);
const signatureTypeIndexIfExists = utils.getSignatureTypeIndexIfExists(signature);
if (_.isUndefined(signatureTypeIndexIfExists)) {
throw new Error(`Unrecognized signatureType in signature: ${signature}`);
@@ -90,6 +94,9 @@ export async function isValidPresignedSignatureAsync(
data: string,
signerAddress: string,
): Promise<boolean> {
+ assert.isWeb3Provider('provider', provider);
+ assert.isHexString('data', data);
+ assert.isETHAddressHex('signerAddress', signerAddress);
const exchangeContract = new ExchangeContract(artifacts.Exchange.compilerOutput.abi, signerAddress, provider);
const isValid = await exchangeContract.preSigned.callAsync(data, signerAddress);
return isValid;
@@ -108,6 +115,10 @@ export async function isValidWalletSignatureAsync(
signature: string,
signerAddress: string,
): Promise<boolean> {
+ assert.isWeb3Provider('provider', provider);
+ assert.isHexString('data', data);
+ assert.isHexString('signature', signature);
+ assert.isETHAddressHex('signerAddress', signerAddress);
// tslint:disable-next-line:custom-no-magic-numbers
const signatureWithoutType = signature.slice(-2);
const walletContract = new IWalletContract(artifacts.IWallet.compilerOutput.abi, signerAddress, provider);
@@ -128,6 +139,10 @@ export async function isValidValidatorSignatureAsync(
signature: string,
signerAddress: string,
): Promise<boolean> {
+ assert.isWeb3Provider('provider', provider);
+ assert.isHexString('data', data);
+ assert.isHexString('signature', signature);
+ assert.isETHAddressHex('signerAddress', signerAddress);
const validatorSignature = parseValidatorSignature(signature);
const exchangeContract = new ExchangeContract(artifacts.Exchange.compilerOutput.abi, signerAddress, provider);
const isValidatorApproved = await exchangeContract.allowedValidators.callAsync(
@@ -192,7 +207,9 @@ export async function ecSignOrderHashAsync(
signerAddress: string,
messagePrefixOpts: MessagePrefixOpts,
): Promise<ECSignature> {
+ assert.isWeb3Provider('provider', provider);
assert.isHexString('orderHash', orderHash);
+ assert.isETHAddressHex('signerAddress', signerAddress);
const web3Wrapper = new Web3Wrapper(provider);
await assert.isSenderAddressAsync('signerAddress', signerAddress, web3Wrapper);
const normalizedSignerAddress = signerAddress.toLowerCase();
@@ -237,6 +254,8 @@ export async function ecSignOrderHashAsync(
* @return Prefixed message
*/
export function addSignedMessagePrefix(message: string, messagePrefixType: MessagePrefixType): string {
+ assert.isString('message', message);
+ assert.doesBelongToStringEnum('messagePrefixType', messagePrefixType, MessagePrefixType);
switch (messagePrefixType) {
case MessagePrefixType.None:
return message;
@@ -266,6 +285,7 @@ export function addSignedMessagePrefix(message: string, messagePrefixType: Messa
* @return An ECSignature object with r,s,v parameters
*/
export function parseECSignature(signature: string): ECSignature {
+ assert.isHexString('signature', signature);
const ecSignatureTypes = [SignatureType.EthSign, SignatureType.EIP712, SignatureType.Trezor];
assert.isOneOfExpectedSignatureTypes(signature, ecSignatureTypes);