-
-
Notifications
You must be signed in to change notification settings - Fork 291
/
logSigners.ts
53 lines (46 loc) · 1.52 KB
/
logSigners.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
import {Signer, SignerLocal, SignerRemote, SignerType} from "@lodestar/validator";
import {LogLevel, Logger} from "@lodestar/utils";
/**
* Log each pubkeys for auditing out keys are loaded from the logs
*/
export function logSigners(logger: Pick<Logger, LogLevel.info>, signers: Signer[]): void {
const localSigners: SignerLocal[] = [];
const remoteSigners: SignerRemote[] = [];
for (const signer of signers) {
switch (signer.type) {
case SignerType.Local:
localSigners.push(signer);
break;
case SignerType.Remote:
remoteSigners.push(signer);
break;
}
}
if (localSigners.length > 0) {
logger.info(`${localSigners.length} local keystores`);
for (const signer of localSigners) {
logger.info(signer.secretKey.toPublicKey().toHex());
}
}
for (const {url, pubkeys} of groupExternalSignersByUrl(remoteSigners)) {
logger.info(`External signers on URL: ${url}`);
for (const pubkey of pubkeys) {
logger.info(pubkey);
}
}
}
/**
* Only used for logging remote signers grouped by URL
*/
function groupExternalSignersByUrl(externalSigners: SignerRemote[]): {url: string; pubkeys: string[]}[] {
const byUrl = new Map<string, {url: string; pubkeys: string[]}>();
for (const externalSigner of externalSigners) {
let x = byUrl.get(externalSigner.url);
if (!x) {
x = {url: externalSigner.url, pubkeys: []};
byUrl.set(externalSigner.url, x);
}
x.pubkeys.push(externalSigner.pubkey);
}
return Array.from(byUrl.values());
}