MCPcopy Create free account
hub / github.com/AztecProtocol/aztec-packages / loadKeystoreFile

Function loadKeystoreFile

yarn-project/node-keystore/src/loader.ts:40–63  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

38 * @throws KeyStoreLoadError When JSON is invalid, schema validation fails, or other IO/parse errors occur.
39 */
40export function loadKeystoreFile(filePath: string): KeyStore {
41 try {
42 const content = readFileSync(filePath, 'utf-8');
43
44 // Parse JSON and validate with Zod schema (following Aztec patterns)
45 return keystoreSchema.parse(JSON.parse(content));
46 } catch (error) {
47 if (error instanceof SyntaxError) {
48 throw new KeyStoreLoadError('Invalid JSON format', filePath, error);
49 }
50 if (error && typeof error === 'object' && 'issues' in error) {
51 const issues = (error as any).issues ?? [];
52 const message =
53 issues
54 .map((e: any) => {
55 const path = Array.isArray(e.path) ? e.path.join('.') : String(e.path ?? 'root');
56 return `${e.message} (${path})`;
57 })
58 .join('. ') || 'Schema validation error';
59 throw new KeyStoreLoadError(`Schema validation failed: ${message}`, filePath, error as unknown as Error);
60 }
61 throw new KeyStoreLoadError(`Unexpected error: ${String(error)}`, filePath, error as Error);
62 }
63}
64
65/**
66 * Loads keystore files from a directory (only .json files).

Callers 7

addValidatorKeysFunction · 0.90
valkeys.test.tsFile · 0.90
generateStakerJsonFunction · 0.90
fromKeystoreFileMethod · 0.90
loadKeystoreDirectoryFunction · 0.85
loadKeystoresFunction · 0.85
validation.test.tsFile · 0.85

Calls 3

joinMethod · 0.80
parseMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected