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; seed = false as any;
} }
if (!seed && seed === undefined) { if (!seed && seed === undefined) {
// @ts-ignore const seedFile = path.join(process.cwd(), ".module-seed");
seed = await prompts.prompts.password({ if (await fileExists(seedFile)) {
name: "module_seed", seed = await fs.readFile(seedFile, "utf8");
message: "Enter your module seed", }
validate: (prev) => prev && bip39.validateMnemonic(prev, wordlist),
}); if (!seed) {
seed = bip39.generateMnemonic(wordlist);
await fs.writeFile(seedFile, seed);
}
} }
const hdKey = seed const hdKey = seed