-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.ts
36 lines (31 loc) · 886 Bytes
/
common.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { ethers } from 'hardhat';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
export type WhitelistRecord = {
account: SignerWithAddress;
limit: number;
chapter: Buffer;
};
export const toWhitelistLeaf = (
address: string,
limit: number,
chapter: Buffer
): Buffer => {
return Buffer.from(
ethers.utils
.solidityKeccak256(
['address', 'uint256', 'bytes32'],
[address, limit, chapter]
)
.slice(2),
'hex'
);
};
export const hashStr = (value: string) => {
return ethers.utils.solidityKeccak256(['string'], [value]);
};
export const buffHashStr = (value: string) => {
return Buffer.from(hashStr(value).slice(2), 'hex');
};
export const hashNum = (value: number) => {
return ethers.utils.solidityKeccak256(['uint256'], [value]);
};