aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-utils/src
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-07-12 21:22:21 +0800
committerFabio Berger <me@fabioberger.com>2018-07-12 21:22:21 +0800
commitd8678d562daac22809ca535a1dacb36ba4ad4e41 (patch)
treeaf4a4e2732b1d38e32a02561059c275896a4fd0b /packages/order-utils/src
parent365e24c1cd0b226510f307270784b379bbcd2d9a (diff)
downloaddexon-sol-tools-d8678d562daac22809ca535a1dacb36ba4ad4e41.tar
dexon-sol-tools-d8678d562daac22809ca535a1dacb36ba4ad4e41.tar.gz
dexon-sol-tools-d8678d562daac22809ca535a1dacb36ba4ad4e41.tar.bz2
dexon-sol-tools-d8678d562daac22809ca535a1dacb36ba4ad4e41.tar.lz
dexon-sol-tools-d8678d562daac22809ca535a1dacb36ba4ad4e41.tar.xz
dexon-sol-tools-d8678d562daac22809ca535a1dacb36ba4ad4e41.tar.zst
dexon-sol-tools-d8678d562daac22809ca535a1dacb36ba4ad4e41.zip
Add assertions to SignatureUtils exported methods
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);