Change seed file with a bip39 mnemonic (#207)
* Change seed file with a bip39 mnemonic * Create helper for bip39 mnemonic * Prod mode on lamassu-update-to-mnemonic script * Fix standard styling issues
This commit is contained in:
parent
809bf5a2a9
commit
d97a33565f
10 changed files with 98 additions and 34 deletions
30
bin/lamassu-update-to-mnemonic
Executable file
30
bin/lamassu-update-to-mnemonic
Executable file
|
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
'use strict'
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const os = require('os')
|
||||
const mnemonicHelpers = require('../lib/mnemonic-helpers')
|
||||
const options = require('../lib/options-loader')()
|
||||
|
||||
if (!options.opts.mnemonicPath && options.opts.seedPath) {
|
||||
const seed = fs.readFileSync(options.opts.seedPath, 'utf8').trim()
|
||||
const mnemonic = mnemonicHelpers.fromSeed(seed)
|
||||
|
||||
if (process.argv[2] === '--prod') {
|
||||
options.opts.mnemonicPath = path.resolve('etc', 'lamassu', 'mnemonics', 'mnemonic.txt')
|
||||
} else {
|
||||
options.opts.mnemonicPath = path.resolve(os.homedir(), '.lamassu', 'mnemonics', 'mnemonic.txt')
|
||||
}
|
||||
|
||||
if (!fs.existsSync(path.dirname(options.opts.mnemonicPath))) {
|
||||
fs.mkdirSync(path.dirname(options.opts.mnemonicPath))
|
||||
}
|
||||
|
||||
if (!fs.existsSync(options.opts.mnemonicPath)) {
|
||||
fs.writeFileSync(options.opts.mnemonicPath, mnemonic, 'utf8')
|
||||
}
|
||||
|
||||
fs.writeFileSync(options.path, JSON.stringify(options.opts, null, '\t'), 'utf8')
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue