@nomicfoundation/hardhat-keystore
Version:
A module for managing keystore files that store a map from IDs to encrypted string values.
89 lines (68 loc) • 2.31 kB
text/typescript
import type { FileManager, KeystoreLoader } from "../types.js";
import { assertHardhatInvariant } from "@nomicfoundation/hardhat-errors";
import { createEmptyEncryptedKeystore } from "../keystores/encryption.js";
import { Keystore } from "../keystores/keystore.js";
export class KeystoreFileLoader implements KeystoreLoader {
readonly
readonly
readonly
constructor(
keystoreFilePath: string,
keystoreDevPasswordFilePath: string,
fileManger: FileManager,
) {
this.
this.
this.
this.
}
public getKeystoreFilePath(): string {
return this.
}
public getKeystoreDevPasswordFilePath(): string {
return this.
}
public async isKeystoreInitialized(): Promise<boolean> {
if (this.
return true;
}
return await this.
}
public async loadKeystore(): Promise<Keystore> {
if (this.
return this.
}
const keystoreFile = await this.
this.
);
const keystore = new Keystore(keystoreFile);
this.
return keystore;
}
public async createUnsavedKeystore({
masterKey,
salt,
}: {
masterKey: Uint8Array;
salt: Uint8Array;
}): Promise<Keystore> {
assertHardhatInvariant(
this.
"Cannot create a new Keystore when one is already loaded",
);
const keystore = new Keystore(
createEmptyEncryptedKeystore({ masterKey, salt }),
);
this.
return keystore;
}
public async saveKeystoreToFile(): Promise<void> {
assertHardhatInvariant(
this.
"Cannot save a keystore that has not been loaded or created",
);
const keystoreFile = this.
await this.
}
}