* move orderParsingUtils from order-utils to connect * Remove many functions from signatureUtils Removed from the exported object, that is. All of them are used in other existing code, so they were all moved to be as local to their usage as possible. * remove orderHashUtils.isValidOrderHash() * Move all *RevertErrors from order-utils... ...into their respective @0x/contracts- packages. * Refactor @0x/order-utils' orderHashUtils away - Move existing routines into @0x/contracts-test-utils - Migrate non-contract-test callers to a newly-exposed getOrderHash() method in DevUtils. * Move all *RevertErrors from @0x/utils... ...into their respective @0x/contracts- packages. * rm transactionHashUtils.isValidTransactionHash() * DevUtils.sol: Fail yarn test if too big to deploy * Refactor @0x/order-utils transactionHashUtils away - Move existing routines into @0x/contracts-test-utils - Migrate non-contract-test callers to a newly-exposed getTransactionHash() method in DevUtils. * Consolidate `Removed export...` CHANGELOG entries * Rm EthBalanceChecker from devutils wrapper exports * Stop importing from '.' or '.../src' * fix builds * fix prettier; dangling promise * increase max bundle size
31 lines
1.6 KiB
TypeScript
31 lines
1.6 KiB
TypeScript
import { assert } from '@0x/assert';
|
|
import { schemas } from '@0x/json-schemas';
|
|
import { eip712Utils } from '@0x/order-utils';
|
|
import { SignedZeroExTransaction, ZeroExTransaction } from '@0x/types';
|
|
import { signTypedDataUtils } from '@0x/utils';
|
|
import * as _ from 'lodash';
|
|
|
|
export const transactionHashUtils = {
|
|
/**
|
|
* Computes the transactionHash for a supplied 0x transaction.
|
|
* @param transaction An object that conforms to the ZeroExTransaction or SignedZeroExTransaction interface definitions.
|
|
* @return Hex encoded string transactionHash from hashing the supplied order.
|
|
*/
|
|
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;
|
|
},
|
|
/**
|
|
* Computes the transactionHash for a supplied 0x transaction.
|
|
* @param transaction An object that conforms to the ZeroExTransaction or SignedZeroExTransaction interface definitions.
|
|
* @return A Buffer containing the resulting transactionHash from hashing the supplied 0x transaction.
|
|
*/
|
|
getTransactionHashBuffer(transaction: ZeroExTransaction | SignedZeroExTransaction): Buffer {
|
|
const typedData = eip712Utils.createZeroExTransactionTypedData(transaction);
|
|
const transactionHashBuff = signTypedDataUtils.generateTypedDataHash(typedData);
|
|
return transactionHashBuff;
|
|
},
|
|
};
|