Update Order-utils to check magic values
This commit is contained in:
@@ -38,7 +38,7 @@ export class IValidatorContract extends BaseContract {
|
||||
* @param hash Message hash that is signed.
|
||||
* @param signerAddress Address that should have signed the given hash.
|
||||
* @param signature Proof of signing.
|
||||
* @returns Validity of order signature.
|
||||
* @returns Magic bytes4 value if the signature is valid. Magic value is bytes4(keccak256("isValidValidatorSignature(address,bytes32,address,bytes)"))
|
||||
*/
|
||||
async callAsync(
|
||||
hash: string,
|
||||
@@ -46,7 +46,7 @@ export class IValidatorContract extends BaseContract {
|
||||
signature: string,
|
||||
callData: Partial<CallData> = {},
|
||||
defaultBlock?: BlockParam,
|
||||
): Promise<boolean> {
|
||||
): Promise<string> {
|
||||
assert.isString('hash', hash);
|
||||
assert.isString('signerAddress', signerAddress);
|
||||
assert.isString('signature', signature);
|
||||
@@ -80,7 +80,7 @@ export class IValidatorContract extends BaseContract {
|
||||
BaseContract._throwIfRevertWithReasonCallResult(rawCallResult);
|
||||
const abiEncoder = self._lookupAbiEncoder('isValidSignature(bytes32,address,bytes)');
|
||||
// tslint:disable boolean-naming
|
||||
const result = abiEncoder.strictDecodeReturnValue<boolean>(rawCallResult);
|
||||
const result = abiEncoder.strictDecodeReturnValue<string>(rawCallResult);
|
||||
// tslint:enable boolean-naming
|
||||
return result;
|
||||
},
|
||||
@@ -104,18 +104,18 @@ export class IValidatorContract extends BaseContract {
|
||||
]);
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
getABIDecodedTransactionData(callData: string): boolean {
|
||||
getABIDecodedTransactionData(callData: string): string {
|
||||
const self = (this as any) as IValidatorContract;
|
||||
const abiEncoder = self._lookupAbiEncoder('isValidSignature(bytes32,address,bytes)');
|
||||
// tslint:disable boolean-naming
|
||||
const abiDecodedCallData = abiEncoder.strictDecode<boolean>(callData);
|
||||
const abiDecodedCallData = abiEncoder.strictDecode<string>(callData);
|
||||
return abiDecodedCallData;
|
||||
},
|
||||
getABIDecodedReturnData(returnData: string): boolean {
|
||||
getABIDecodedReturnData(returnData: string): string {
|
||||
const self = (this as any) as IValidatorContract;
|
||||
const abiEncoder = self._lookupAbiEncoder('isValidSignature(bytes32,address,bytes)');
|
||||
// tslint:disable boolean-naming
|
||||
const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<boolean>(returnData);
|
||||
const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<string>(returnData);
|
||||
return abiDecodedReturnData;
|
||||
},
|
||||
};
|
||||
@@ -208,7 +208,7 @@ export class IValidatorContract extends BaseContract {
|
||||
outputs: [
|
||||
{
|
||||
name: 'isValid',
|
||||
type: 'bool',
|
||||
type: 'bytes4',
|
||||
},
|
||||
],
|
||||
payable: false,
|
||||
|
@@ -37,14 +37,14 @@ export class IWalletContract extends BaseContract {
|
||||
* since they don't modify state.
|
||||
* @param hash Message hash that is signed.
|
||||
* @param signature Proof of signing.
|
||||
* @returns Validity of order signature.
|
||||
* @returns Magic bytes4 value if the signature is valid. Magic value is bytes4(keccak256("isValidWalletSignature(bytes32,address,bytes)"))
|
||||
*/
|
||||
async callAsync(
|
||||
hash: string,
|
||||
signature: string,
|
||||
callData: Partial<CallData> = {},
|
||||
defaultBlock?: BlockParam,
|
||||
): Promise<boolean> {
|
||||
): Promise<string> {
|
||||
assert.isString('hash', hash);
|
||||
assert.isString('signature', signature);
|
||||
assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [
|
||||
@@ -73,7 +73,7 @@ export class IWalletContract extends BaseContract {
|
||||
BaseContract._throwIfRevertWithReasonCallResult(rawCallResult);
|
||||
const abiEncoder = self._lookupAbiEncoder('isValidSignature(bytes32,bytes)');
|
||||
// tslint:disable boolean-naming
|
||||
const result = abiEncoder.strictDecodeReturnValue<boolean>(rawCallResult);
|
||||
const result = abiEncoder.strictDecodeReturnValue<string>(rawCallResult);
|
||||
// tslint:enable boolean-naming
|
||||
return result;
|
||||
},
|
||||
@@ -94,18 +94,18 @@ export class IWalletContract extends BaseContract {
|
||||
]);
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
getABIDecodedTransactionData(callData: string): boolean {
|
||||
getABIDecodedTransactionData(callData: string): string {
|
||||
const self = (this as any) as IWalletContract;
|
||||
const abiEncoder = self._lookupAbiEncoder('isValidSignature(bytes32,bytes)');
|
||||
// tslint:disable boolean-naming
|
||||
const abiDecodedCallData = abiEncoder.strictDecode<boolean>(callData);
|
||||
const abiDecodedCallData = abiEncoder.strictDecode<string>(callData);
|
||||
return abiDecodedCallData;
|
||||
},
|
||||
getABIDecodedReturnData(returnData: string): boolean {
|
||||
getABIDecodedReturnData(returnData: string): string {
|
||||
const self = (this as any) as IWalletContract;
|
||||
const abiEncoder = self._lookupAbiEncoder('isValidSignature(bytes32,bytes)');
|
||||
// tslint:disable boolean-naming
|
||||
const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<boolean>(returnData);
|
||||
const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<string>(returnData);
|
||||
return abiDecodedReturnData;
|
||||
},
|
||||
};
|
||||
@@ -194,7 +194,7 @@ export class IWalletContract extends BaseContract {
|
||||
outputs: [
|
||||
{
|
||||
name: 'isValid',
|
||||
type: 'bool',
|
||||
type: 'bytes4',
|
||||
},
|
||||
],
|
||||
payable: false,
|
||||
|
@@ -150,4 +150,6 @@ export const constants = {
|
||||
MULTI_ASSET_METHOD_ABI,
|
||||
ERC1155_METHOD_ABI,
|
||||
STATIC_CALL_METHOD_ABI,
|
||||
IS_VALID_WALLET_SIGNATURE_MAGIC_VALUE: '0xb0671381',
|
||||
IS_VALID_VALIDATOR_SIGNATURE_MAGIC_VALUE: '0x42b38674',
|
||||
};
|
||||
|
@@ -17,6 +17,7 @@ import * as ethUtil from 'ethereumjs-util';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { assert } from './assert';
|
||||
import { constants } from './constants';
|
||||
import { eip712Utils } from './eip712_utils';
|
||||
import { orderHashUtils } from './order_hash';
|
||||
import { transactionHashUtils } from './transaction_hash';
|
||||
@@ -135,8 +136,8 @@ export const signatureUtils = {
|
||||
// tslint:disable-next-line:custom-no-magic-numbers
|
||||
const signatureWithoutType = signature.slice(0, -2);
|
||||
const walletContract = new IWalletContract(signerAddress, provider);
|
||||
const isValid = await walletContract.isValidSignature.callAsync(data, signatureWithoutType);
|
||||
return isValid;
|
||||
const magicValue = await walletContract.isValidSignature.callAsync(data, signatureWithoutType);
|
||||
return magicValue === constants.IS_VALID_WALLET_SIGNATURE_MAGIC_VALUE;
|
||||
},
|
||||
/**
|
||||
* Verifies that the provided validator signature is valid according to the 0x Protocol smart contracts
|
||||
@@ -169,12 +170,12 @@ export const signatureUtils = {
|
||||
}
|
||||
|
||||
const validatorContract = new IValidatorContract(signerAddress, provider);
|
||||
const isValid = await validatorContract.isValidSignature.callAsync(
|
||||
const magicValue = await validatorContract.isValidSignature.callAsync(
|
||||
data,
|
||||
signerAddress,
|
||||
validatorSignature.signature,
|
||||
);
|
||||
return isValid;
|
||||
return magicValue === constants.IS_VALID_VALIDATOR_SIGNATURE_MAGIC_VALUE;
|
||||
},
|
||||
/**
|
||||
* Checks if the supplied elliptic curve signature corresponds to signing `data` with
|
||||
|
Reference in New Issue
Block a user