Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
createOrderTypedData: (order: Order): EIP712TypedData => {
assert.doesConformToSchema('order', order, schemas.orderSchema, [schemas.hexSchema]);
const normalizedOrder = _.mapValues(order, value => {
return !_.isString(value) ? value.toString() : value;
});
const partialDomain = {
chainId: order.chainId,
verifyingContract: order.exchangeAddress,
};
// Since we are passing in the EXCHANGE_ORDER_SCHEMA
// order paramaters that are not in there get ignored at hashing time
const typedData = eip712Utils.createTypedData(
constants.EXCHANGE_ORDER_SCHEMA.name,
{ Order: constants.EXCHANGE_ORDER_SCHEMA.parameters },
normalizedOrder,
partialDomain,
);
return typedData;
getOrderHashBuffer(order: SignedOrder | Order): Buffer {
try {
assert.doesConformToSchema('order', order, schemas.orderSchema, [schemas.hexSchema]);
} catch (error) {
if (_.includes(error.message, INVALID_TAKER_FORMAT)) {
const errMsg = `Order taker must be of type string. If you want anyone to be able to fill an order - pass ${NULL_ADDRESS}`;
throw new Error(errMsg);
}
throw error;
}
const typedData = eip712Utils.createOrderTypedData(order);
const orderHashBuff = signTypedDataUtils.generateTypedDataHash(typedData);
return orderHashBuff;
},
};
getTransactionHashHex(transaction: ZeroExTransaction | SignedZeroExTransaction): string {
assert.doesConformToSchema('transaction', transaction, schemas.zeroExTransactionSchema, [schemas.hexSchema]);
const transactionHashBuff = transactionHashUtils.getTransactionHashBuffer(transaction);
const transactionHashHex = `0x${transactionHashBuff.toString('hex')}`;
return transactionHashHex;
},
/**
async ecSignTypedDataOrderAsync(
supportedProvider: SupportedProvider,
order: Order,
signerAddress: string,
): Promise {
const provider = providerUtils.standardizeOrThrow(supportedProvider);
assert.isETHAddressHex('signerAddress', signerAddress);
assert.doesConformToSchema('order', order, schemas.orderSchema, [schemas.hexSchema]);
const web3Wrapper = new Web3Wrapper(provider);
await assert.isSenderAddressAsync('signerAddress', signerAddress, web3Wrapper);
const normalizedSignerAddress = signerAddress.toLowerCase();
const typedData = eip712Utils.createOrderTypedData(order);
try {
const signature = await web3Wrapper.signTypedDataAsync(normalizedSignerAddress, typedData);
const ecSignatureRSV = parseSignatureHexAsRSV(signature);
const signatureBuffer = Buffer.concat([
ethUtil.toBuffer(ecSignatureRSV.v),
ethUtil.toBuffer(ecSignatureRSV.r),
ethUtil.toBuffer(ecSignatureRSV.s),
ethUtil.toBuffer(SignatureType.EIP712),
]);
const signatureHex = `0x${signatureBuffer.toString('hex')}`;
return {
...order,