refactor: read module seed from file, if env not set, and fall back to generating one and saving it to disk

This commit is contained in:
Derrick Hammer 2023-09-04 05:51:20 -04:00
parent a5818bc17d
commit 9844d8edae
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 9 additions and 6 deletions

View File

@ -50,12 +50,15 @@ if (["0", "false"].includes(seed as string)) {
seed = false as any;
}
if (!seed && seed === undefined) {
// @ts-ignore
seed = await prompts.prompts.password({
name: "module_seed",
message: "Enter your module seed",
validate: (prev) => prev && bip39.validateMnemonic(prev, wordlist),
});
const seedFile = path.join(process.cwd(), ".module-seed");
if (await fileExists(seedFile)) {
seed = await fs.readFile(seedFile, "utf8");
}
if (!seed) {
seed = bip39.generateMnemonic(wordlist);
await fs.writeFile(seedFile, seed);
}
}
const hdKey = seed