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;
|
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
|
||||||
|
|
Loading…
Reference in New Issue