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:
parent
a5818bc17d
commit
9844d8edae
15
src/index.ts
15
src/index.ts
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue