Dev script to recreate seeds file from mnemonic
This commit is contained in:
parent
cdfc84a96a
commit
d253c4fa00
1 changed files with 26 additions and 0 deletions
26
dev/recreate-seeds.js
Normal file
26
dev/recreate-seeds.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
'use strict'
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const os = require('os')
|
||||
const bip39 = require('bip39')
|
||||
const options = require('../lib/options-loader')()
|
||||
|
||||
if (options.opts.mnemonicPath && !options.opts.seedPath) {
|
||||
const mnemonic = fs.readFileSync(options.opts.mnemonicPath, 'utf8')
|
||||
const seed = bip39.mnemonicToEntropy(mnemonic.split('\n').join(' ').trim()).toString('hex')
|
||||
|
||||
options.opts.seedPath = path.resolve(os.homedir(), '.lamassu', 'seeds', 'seed.txt')
|
||||
|
||||
if (!fs.existsSync(path.dirname(options.opts.seedPath))) {
|
||||
fs.mkdirSync(path.dirname(options.opts.seedPath))
|
||||
}
|
||||
|
||||
if (!fs.existsSync(options.opts.seedPath)) {
|
||||
fs.writeFileSync(options.opts.seedPath, seed, 'utf8')
|
||||
}
|
||||
|
||||
fs.writeFileSync(options.path, JSON.stringify(options.opts, null, '\t'), 'utf8')
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue