@0x/contracts-test-utils: Add hexHash() to hex_utils.

This commit is contained in:
Lawrence Forman 2019-09-19 05:41:00 -04:00 committed by Lawrence Forman
parent 86106713dd
commit 0270777cfc
3 changed files with 21 additions and 1 deletions

View File

@ -86,6 +86,10 @@
"note": "Tweaks/Upgrades to `hex_utils`, most notably `hexSlice()`", "note": "Tweaks/Upgrades to `hex_utils`, most notably `hexSlice()`",
"pr": 2155 "pr": 2155
}, },
{
"note": "Add `hexHash()` to `hex_utils`",
"pr": 2155
},
{ {
"note": "Add `shortZip()` to `lang_utils.ts`", "note": "Add `shortZip()` to `lang_utils.ts`",
"pr": 2155 "pr": 2155

View File

@ -58,6 +58,13 @@ export function hexSlice(n: Numberish, start: number, end?: number): string {
return '0x'.concat(hex.substring(sliceStart, sliceEnd)); return '0x'.concat(hex.substring(sliceStart, sliceEnd));
} }
/**
* Get the keccak hash of some data.
*/
export function hexHash(n: Numberish): string {
return ethUtil.bufferToHex(ethUtil.sha3(ethUtil.toBuffer(toHex(n))));
}
/** /**
* Convert a string, a number, or a BigNumber into a hex string. * Convert a string, a number, or a BigNumber into a hex string.
* Works with negative numbers, as well. * Works with negative numbers, as well.

View File

@ -28,7 +28,16 @@ export { bytes32Values, testCombinatoriallyWithReferenceFunc, uint256Values } fr
export { TransactionFactory } from './transaction_factory'; export { TransactionFactory } from './transaction_factory';
export { MutatorContractFunction, TransactionHelper } from './transaction_helper'; export { MutatorContractFunction, TransactionHelper } from './transaction_helper';
export { testWithReferenceFuncAsync } from './test_with_reference'; export { testWithReferenceFuncAsync } from './test_with_reference';
export { hexConcat, hexLeftPad, hexInvert, hexSlice, hexRandom, hexRightPad, toHex } from './hex_utils'; export {
hexConcat,
hexHash,
hexLeftPad,
hexInvert,
hexSlice,
hexRandom,
hexRightPad,
toHex,
} from './hex_utils';
export { export {
BatchMatchOrder, BatchMatchOrder,
ContractName, ContractName,