/
index.ts
54 lines (49 loc) · 1.41 KB
/
index.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* Parses object in format { "key.key2.key3" : value } into { key: { key2: {key3: value } } }
* @param object object to parse
* @param key string to split
* @param value value to make it equal to
*/
export function set(object, key, value) {
let current = object;
const tokens = key.split('.');
const last = tokens.pop();
tokens.forEach(token => {
current[token] = typeof current[token] == 'object' ? current[token] : {};
current = current[token];
});
current[last] = value;
return object;
}
/**
* Should invert the object (keys becomes values and values becomes keys)
* @param object
*/
export function invert(object) {
const returnee = {};
for (const key in object) {
if (!object.hasOwnProperty(key)) continue;
returnee[object[key]] = key;
}
return returnee;
}
export function signedInfuraLink(
infura: string,
network: string = 'mainnet',
): string {
return `https://${network}.infura.com/v3/${infura}`;
}
export function isLegacyResolver(resolverAddress: string): boolean {
return [
'0xa1cac442be6673c49f8e74ffc7c4fd746f3cbd0d',
'0x878bc2f3f717766ab69c0a5f9a6144931e61aed3',
].includes(resolverAddress.toLowerCase());
}
export function hexToBytes(hexString: string): number[] {
const hex = hexString.replace(/^0x/i, '');
const bytes: number[] = [];
for (let c = 0; c < hex.length; c += 2) {
bytes.push(parseInt(hex.substr(c, 2), 16));
}
return bytes;
}