watcher-ts/packages/ipld-eth-client/src/utils.ts
Ashwin Phatak 4e0ef7c852
Implement typescript strict mode and ESLint in ipld-eth-client and cache packages (#37)
* Set up typescript build.

* Setup eslint in cache package.

* Automatic lint fixes.

* Fix typescript return types.

* Fix typescript argument type warnings.

* Set up typescript build and eslint.

* Automatic lint fixes.

* Fix typescript explicit any warnings.

* Add argument types.

* Fix return type warnings.

* Fix typescript errors.

* Implement declaration in types directory.

Co-authored-by: nikugogoi <95nikass@gmail.com>
2021-06-04 12:04:12 +05:30

25 lines
743 B
TypeScript

import leftPad from 'left-pad';
import { ethers } from 'ethers';
export const padKey = (input: string): string =>
leftPad(ethers.utils.hexlify(input).replace('0x', ''), 64, '0');
export const getMappingSlot = (mappingSlot: string, key: string): string => {
const mappingSlotPadded = padKey(mappingSlot);
const keyPadded = padKey(key);
const fullKey = keyPadded.concat(mappingSlotPadded);
const slot = ethers.utils.keccak256(`0x${fullKey}`);
return slot;
};
export const getStorageLeafKey = (slot: string): string => ethers.utils.keccak256(slot);
export const topictoAddress = (topic: string): string => {
return ethers.utils.getAddress(
ethers.utils.hexZeroPad(
ethers.utils.hexStripZeros(topic), 20
)
);
};